Submission #920657

#TimeUsernameProblemLanguageResultExecution timeMemory
920657rainboy조개 줍기 (KOI17_shell)C++17
100 / 100
178 ms35668 KiB
#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)

shell.cpp: In function 'int main()':
shell.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
shell.cpp:15:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |    scanf("%d", &aa[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~
shell.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%s%d%d", s, &i, &j), i--, j--;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...