# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28452 | Sorry AcornCkiGuiziTeam (#68) | Test Data Creation (FXCUP2_testdata) | C++14 | 189 ms | 219152 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
using namespace std;
int a[90009];
int b[90009];
int d[606][303][303];
int main() {
int i, j, k, l, m, n, t;
scanf("%d%d", &m, &n);
for (i = 0; i < n * m; i++) scanf("%d", &a[i]);
d[0][0][0] = a[0];
for (i = 1; i <= n + m - 2; i++) for (j = max(0, i - m + 1); j <= i && j < n; j++) for (k = max(0, i - n + 1); k <= i && k < m; k++) {
t = 2e9;
if (j && k) t = min(t, d[i - 1][j - 1][k - 1]);
if (i - j && k) t = min(t, d[i - 1][j][k - 1]);
if (j && i - k) t = min(t, d[i - 1][j - 1][k]);
if (i - j && i - k) t = min(t, d[i - 1][j][k]);
if (j * m + i - j == k * n + i - k) t += a[j * m + i - j];
else t += a[j * m + i - j] + a[k * n + i - k];
d[i][j][k] = t;
}
printf("%d\n", d[n + m - 2][n - 1][m - 1]);
i = n + m - 2;
j = n - 1;
k = m - 1;
while (i) {
b[j * m + i - j] = b[k * n + i - k] = 1;
t = d[i][j][k];
if (j * m + i - j == k * n + i - k) t -= a[j * m + i - j];
else t -= a[j * m + i - j] + a[k * n + i - k];
i--;
if (j && k && t == d[i][j - 1][k - 1]) {
j--;
k--;
continue;
}
if (i - j && k && t == d[i][j][k - 1]) {
k--;
continue;
}
if (j && i - k && t == d[i][j - 1][k]) {
j--;
continue;
}
}
b[0] = 1;
for (i = 0; i < n; i++, puts("")) for (j = 0; j < m; j++) printf("%d ", b[i * m + j]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |