# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
472978 | 2021-09-14T17:02:43 Z | rainboy | Spirale (COCI18_spirale) | C | 48 ms | 312 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 280 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 280 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 48 ms | 312 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |