답안 #338048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338048 2020-12-22T11:11:39 Z boykut UFO (IZhO14_ufo) C++14
30 / 100
2000 ms 19880 KB
#include <bits/stdc++.h>

using namespace std;

signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   
   int n, m, k, r, p;
   cin >> n >> m >> r >> k >> p;
   
   vector < vector <int> > a(1+n, vector <int> (1+m,0));
   vector < vector <int> > sum(1+n, vector <int> (1+m,0));
   
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         cin >> a[i][j];
      }
   }
   
   for (int tmp = k; tmp--;) {
      char c; cin >> c;
      int pos, h; cin >> pos >> h;
      if (c == 'N') {
         int cnt = 0;
         for (int i = 1; i <= n; i++) {
            if (a[i][pos] >= h) {
               a[i][pos]--;
               cnt++;
               if (cnt == r) break;
            }
         }
      } else if (c == 'S') {
         int cnt = 0;
         for (int i = n; i >= 1; i--) {
            if (a[i][pos] >= h) {
               a[i][pos]--;
               cnt++;
               if (cnt == r) break;
            }
         }
      } else if (c == 'W') {
         int cnt = 0;
         for (int j = 1; j <= m; j++) {
            if (a[pos][j] >= h) {
               a[pos][j]--;
               cnt++;
               if (cnt == r) break;
            }
         }
      } else {
         int cnt = 0;
         for (int j = m; j >= 1; j--) {
            if (a[pos][j] >= h) {
               a[pos][j]--;
               cnt++;
               if (cnt == r) break;
            }
         }
      }
   }
   
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         sum[i][j] = a[i][j];
         sum[i][j] += sum[i-1][j];
         sum[i][j] += sum[i][j-1];
         sum[i][j] -= sum[i-1][j-1];
      }
   }
   
   int ans = 0, A, i2, j2;
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         i2 = i + p - 1, j2 = j + p - 1;
         if (i2 <= n && j2 <= m) {
            A = sum[i2][j2];
            A -= sum[i2][j-1];
            A -= sum[i-1][j2];
            A += sum[i-1][j-1];
            if (A > ans)
               ans = A;
         }
      }
   }
   
   cout << ans << '\n';
   
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 17 ms 748 KB Output is correct
6 Correct 68 ms 4332 KB Output is correct
7 Execution timed out 2080 ms 9316 KB Time limit exceeded
8 Execution timed out 2033 ms 9316 KB Time limit exceeded
9 Execution timed out 2070 ms 8744 KB Time limit exceeded
10 Execution timed out 2090 ms 9316 KB Time limit exceeded
11 Execution timed out 2086 ms 9236 KB Time limit exceeded
12 Execution timed out 2074 ms 9316 KB Time limit exceeded
13 Execution timed out 2087 ms 17644 KB Time limit exceeded
14 Execution timed out 2085 ms 9236 KB Time limit exceeded
15 Execution timed out 2085 ms 9316 KB Time limit exceeded
16 Execution timed out 2088 ms 9236 KB Time limit exceeded
17 Execution timed out 2085 ms 17516 KB Time limit exceeded
18 Execution timed out 2071 ms 17260 KB Time limit exceeded
19 Execution timed out 2088 ms 10460 KB Time limit exceeded
20 Execution timed out 2086 ms 19880 KB Time limit exceeded