# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
920657 | 2024-02-02T20:55:19 Z | rainboy | None (KOI17_shell) | C++17 | 178 ms | 35668 KB |
#include <stdio.h> #define N 1500 int max(int a, int b) { return a > b ? a : b; } int main() { static int aa[N][N], dp[N][N], dd[N][N]; int n, h, i, il, ir, j, jl, jr; long long sum; scanf("%d", &n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf("%d", &aa[i][j]); for (i = 0; i < n; i++) for (j = 0; j < n; j++) dp[i][j] = (i == 0 && j == 0 ? 0 : max(i == 0 ? -1 : dp[i - 1][j], j == 0 ? -1 : dp[i][j - 1])) + aa[i][j]; sum = 0; for (i = 0; i < n; i++) for (j = 0; j < n; j++) sum += dp[i][j]; for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (i + 1 < n && j > 0) dd[i][j] = dp[i][j] - dp[i + 1][j - 1]; printf("%lld\n", sum); for (h = 0; h < n; h++) { static char s[2]; scanf("%s%d%d", s, &i, &j), i--, j--; if (s[0] == 'U') { il = i, jl = j, ir = i, jr = j; while (jl <= jr) { sum += jr - jl + 1; if (il + 1 < n && jl > 0) dd[il][jl]++; if (ir > 0 && jr + 1 < n) dd[ir - 1][jr + 1]--; if (il == n - 1 && jl == n - 1) break; if (il + 1 < n && (jl == 0 || dd[il][jl] > 0)) il++; else jl++; if (jr + 1 < n && (ir == 0 || dd[ir - 1][jr + 1] < 0)) jr++; else ir++; } } else { il = i, jl = j, ir = i, jr = j; while (jl <= jr) { sum -= jr - jl + 1; if (il + 1 < n && jl > 0) dd[il][jl]--; if (ir > 0 && jr + 1 < n) dd[ir - 1][jr + 1]++; if (il == n - 1 && jl == n - 1) break; if (il + 1 < n && (jl == 0 || dd[il][jl] >= 0)) il++; else jl++; if (jr + 1 < n && (ir == 0 || dd[ir - 1][jr + 1] <= 0)) jr++; else ir++; } } printf("%lld\n", sum); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7004 KB | Output is correct |
2 | Correct | 2 ms | 7004 KB | Output is correct |
3 | Correct | 2 ms | 7004 KB | Output is correct |
4 | Correct | 3 ms | 7004 KB | Output is correct |
5 | Correct | 3 ms | 7004 KB | Output is correct |
6 | Correct | 2 ms | 7004 KB | Output is correct |
7 | Correct | 2 ms | 7004 KB | Output is correct |
8 | Correct | 2 ms | 7004 KB | Output is correct |
9 | Correct | 2 ms | 7004 KB | Output is correct |
10 | Correct | 2 ms | 7004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 157 ms | 31056 KB | Output is correct |
2 | Correct | 138 ms | 31060 KB | Output is correct |
3 | Correct | 138 ms | 31128 KB | Output is correct |
4 | Correct | 139 ms | 31316 KB | Output is correct |
5 | Correct | 136 ms | 31056 KB | Output is correct |
6 | Correct | 138 ms | 31060 KB | Output is correct |
7 | Correct | 141 ms | 31252 KB | Output is correct |
8 | Correct | 137 ms | 31008 KB | Output is correct |
9 | Correct | 141 ms | 31064 KB | Output is correct |
10 | Correct | 137 ms | 31136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7004 KB | Output is correct |
2 | Correct | 2 ms | 7004 KB | Output is correct |
3 | Correct | 2 ms | 7004 KB | Output is correct |
4 | Correct | 3 ms | 7004 KB | Output is correct |
5 | Correct | 3 ms | 7004 KB | Output is correct |
6 | Correct | 2 ms | 7004 KB | Output is correct |
7 | Correct | 2 ms | 7004 KB | Output is correct |
8 | Correct | 2 ms | 7004 KB | Output is correct |
9 | Correct | 2 ms | 7004 KB | Output is correct |
10 | Correct | 157 ms | 31056 KB | Output is correct |
11 | Correct | 138 ms | 31060 KB | Output is correct |
12 | Correct | 138 ms | 31128 KB | Output is correct |
13 | Correct | 139 ms | 31316 KB | Output is correct |
14 | Correct | 136 ms | 31056 KB | Output is correct |
15 | Correct | 138 ms | 31060 KB | Output is correct |
16 | Correct | 141 ms | 31252 KB | Output is correct |
17 | Correct | 137 ms | 31008 KB | Output is correct |
18 | Correct | 141 ms | 31064 KB | Output is correct |
19 | Correct | 137 ms | 31136 KB | Output is correct |
20 | Correct | 2 ms | 7004 KB | Output is correct |
21 | Correct | 153 ms | 35376 KB | Output is correct |
22 | Correct | 148 ms | 35220 KB | Output is correct |
23 | Correct | 151 ms | 35668 KB | Output is correct |
24 | Correct | 178 ms | 35584 KB | Output is correct |
25 | Correct | 174 ms | 35252 KB | Output is correct |
26 | Correct | 169 ms | 35412 KB | Output is correct |
27 | Correct | 137 ms | 31056 KB | Output is correct |
28 | Correct | 140 ms | 31128 KB | Output is correct |
29 | Correct | 148 ms | 35360 KB | Output is correct |
30 | Correct | 148 ms | 35356 KB | Output is correct |
31 | Correct | 176 ms | 35612 KB | Output is correct |
32 | Correct | 178 ms | 35464 KB | Output is correct |
33 | Correct | 137 ms | 31124 KB | Output is correct |
34 | Correct | 137 ms | 31060 KB | Output is correct |