# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
472978 | rainboy | Spirale (COCI18_spirale) | C11 | 48 ms | 312 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 <stdio.h>
#define N 50
#define M 50
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int solve(int i, int j) {
if (i == 0 && j == 0)
return 1;
if (i < j && j <= -i)
return (-i * 2 - 1) * (-i * 2 - 1) + j - i;
if (-j < i && i <= j)
return (j * 2 - 1) * (j * 2 - 1) + j * 2 + i + j;
if (-i < -j && -j <= i)
return (i * 2 - 1) * (i * 2 - 1) + i * 4 - j + i;
if (j < -i && -i <= -j)
return (-j * 2 - 1) * (-j * 2 - 1) + -j * 6 - i - j;
return -1;
}
int main() {
static int ii[N * M], jj[N * M], tt[N * M];
int n, m, k, h, i, j;
scanf("%d%d%d", &n, &m, &k);
for (h = 0; h < k; h++)
scanf("%d%d%d", &ii[h], &jj[h], &tt[h]);
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
int a = INF;
for (h = 0; h < k; h++)
a = min(a, solve(i - ii[h], tt[h] == 0 ? j - jj[h] : jj[h] - j));
printf("%d ", a);
}
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |