# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
403410 | 2021-05-13T06:58:37 Z | shenxy | None (KOI17_shell) | C++11 | 2000 ms | 18016 KB |
#include <cstdio> #include <algorithm> #include <set> using namespace std; typedef pair<int, int> ii; int main() { int N; scanf("%d", &N); if (N <= 100) { int A[N][N], S[N][N]; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) scanf("%d", &A[i][j]); } int r, c, ans = 0; char op; S[0][0] = A[0][0]; for (int i = 1; i < N; ++i) S[i][0] = S[i - 1][0] + A[i][0], S[0][i] = S[0][i - 1] + A[0][i]; for (int i = 1; i < N; ++i) { for (int j = 1; j < N; ++j) S[i][j] = max(S[i - 1][j], S[i][j - 1]) + A[i][j]; } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) ans += S[i][j]; } printf("%d\n", ans); for (int i = 0; i < N; ++i) { scanf(" %c %d %d", &op, &r, &c); if (op == 'U') ++A[r - 1][c - 1]; else --A[r - 1][c - 1]; S[0][0] = A[0][0]; ans = 0; for (int i = 1; i < N; ++i) S[i][0] = S[i - 1][0] + A[i][0], S[0][i] = S[0][i - 1] + A[0][i]; for (int i = 1; i < N; ++i) { for (int j = 1; j < N; ++j) S[i][j] = max(S[i - 1][j], S[i][j - 1]) + A[i][j]; } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) ans += S[i][j]; } printf("%d\n", ans); } } else { int A[N + 1][N + 1], S[N + 1][N + 1]; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) scanf("%d", &A[i][j]); } int r[N], c[N], ans[N + 1]; char op; for (int i = 0; i < N; ++i) scanf(" %c %d %d", &op, &r[i], &c[i]), --A[r[i]][c[i]]; for (int i = 0; i <= N; ++i) S[0][i] = S[i][0] = 0; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) S[i][j] = max(S[i - 1][j], S[i][j - 1]) + A[i][j]; } ans[N] = 0; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) ans[N] += S[i][j]; } for (int i = N - 1; i >= 0; --i) { ++A[r[i]][c[i]]; set<ii> pq; pq.insert(ii(r[i], c[i])); ans[i] = ans[i + 1]; while (!pq.empty()) { int j = pq.begin() -> first, k = pq.begin() -> second; pq.erase(pq.begin()); if (S[j][k] == max(S[j - 1][k], S[j][k - 1]) + A[j][k]) continue; ++ans[i]; S[j][k] = max(S[j - 1][k], S[j][k - 1]) + A[j][k]; if (j != N) pq.insert(ii(j + 1, k)); if (k != N) pq.insert(ii(j, k + 1)); } } for (int i = 0; i <= N; ++i) printf("%d\n", ans[i]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 332 KB | Output is correct |
2 | Correct | 6 ms | 332 KB | Output is correct |
3 | Correct | 6 ms | 332 KB | Output is correct |
4 | Correct | 7 ms | 332 KB | Output is correct |
5 | Correct | 7 ms | 332 KB | Output is correct |
6 | Correct | 6 ms | 332 KB | Output is correct |
7 | Correct | 7 ms | 352 KB | Output is correct |
8 | Correct | 6 ms | 332 KB | Output is correct |
9 | Correct | 6 ms | 332 KB | Output is correct |
10 | Correct | 6 ms | 360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 504 ms | 18016 KB | Output is correct |
2 | Correct | 455 ms | 17924 KB | Output is correct |
3 | Execution timed out | 2084 ms | 17888 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 332 KB | Output is correct |
2 | Correct | 6 ms | 332 KB | Output is correct |
3 | Correct | 6 ms | 332 KB | Output is correct |
4 | Correct | 7 ms | 332 KB | Output is correct |
5 | Correct | 7 ms | 332 KB | Output is correct |
6 | Correct | 6 ms | 332 KB | Output is correct |
7 | Correct | 7 ms | 352 KB | Output is correct |
8 | Correct | 6 ms | 332 KB | Output is correct |
9 | Correct | 6 ms | 332 KB | Output is correct |
10 | Correct | 504 ms | 18016 KB | Output is correct |
11 | Correct | 455 ms | 17924 KB | Output is correct |
12 | Execution timed out | 2084 ms | 17888 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |