# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
920657 | rainboy | 조개 줍기 (KOI17_shell) | C++17 | 178 ms | 35668 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 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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |