Submission #345328

# Submission time Handle Problem Language Result Execution time Memory
345328 2021-01-07T07:28:30 Z bachaquer UFO (IZhO14_ufo) C++14
30 / 100
2000 ms 8948 KB
#include <bits/stdc++.h>

#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n, m, r, k, p;
    cin >> n >> m >> r >> k >> p;
    ll l[n][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> l[i][j];
        }
    }
    char c;
    int x, h;
    for (int t = 0; t < k; t++) {
        cin >> c >> x >> h;
        ll ups = 0;
        if (c == 'W') {
            for (int j = 0; j < m && ups < r; j++) {
                if (l[x - 1][j] >= h) {
                    l[x - 1][j]--;
                    ups++;
                }
            }
        }
        else if (c == 'N') {
            for (int i = 0; i < n && ups < r; i++) {
                if (l[i][x - 1] >= h) {
                    l[i][x - 1]--;
                    ups++;
                }
            }
        }
        else if (c == 'E') {
            for (int j = m - 1; j >= 0 && ups < r; j--) {
                if (l[x - 1][j] >= h) {
                    l[x - 1][j]--;
                    ups++;
                }
            }
        }
        else if (c == 'S') {
            for (int i = n - 1; i >= 0 && ups < r; i--) {
                if (l[i][x - 1] >= h) {
                    l[i][x - 1]--;
                    ups++;
                }
            }
        }
    }
    ll mx = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ll sum = 0;
            if (p > j + 1 || p > i + 1) continue;
            bool br = false;
            for (int up = i; up >= i - p + 1; up--) {
                for (int left = j; left >= j - p + 1; left--) {
                    sum += l[up][left];
                    if (l[up][left] == 0) {
                        br = true;
                        break;
                    }
                }
                if (br) break;
            }
            if (br) continue;
            mx = max(sum, mx);
        }
    }
    cout << mx;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 5 ms 492 KB Output is correct
5 Correct 17 ms 1388 KB Output is correct
6 Correct 89 ms 4972 KB Output is correct
7 Execution timed out 2083 ms 8812 KB Time limit exceeded
8 Execution timed out 2065 ms 8940 KB Time limit exceeded
9 Execution timed out 2059 ms 8940 KB Time limit exceeded
10 Execution timed out 2027 ms 8904 KB Time limit exceeded
11 Execution timed out 2060 ms 8556 KB Time limit exceeded
12 Execution timed out 2072 ms 8892 KB Time limit exceeded
13 Execution timed out 2040 ms 8948 KB Time limit exceeded
14 Execution timed out 2055 ms 8624 KB Time limit exceeded
15 Execution timed out 2068 ms 8940 KB Time limit exceeded
16 Execution timed out 2069 ms 8556 KB Time limit exceeded
17 Execution timed out 2061 ms 8812 KB Time limit exceeded
18 Execution timed out 2083 ms 7728 KB Time limit exceeded
19 Execution timed out 2033 ms 8940 KB Time limit exceeded
20 Execution timed out 2033 ms 8940 KB Time limit exceeded