Submission #154491

# Submission time Handle Problem Language Result Execution time Memory
154491 2019-09-22T07:30:57 Z srvlt UFO (IZhO14_ufo) C++14
10 / 100
2000 ms 14600 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("sse2,avx")
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
//#define int long long
using namespace std;

void dout() {
    cerr << endl;
}

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, r, k, p;

void solve(int tc) {
    cin >> n >> m >> r >> k >> p;
    vector <vector <int> > g(n, vector <int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> g[i][j];
        }
    }
    for (int i = 0; i < k; i++) {
        char c;
        int x, y;
        cin >> c >> x >> y;
        x--;
        int cur = r;
        if (c == 'W') {
            for (int j = 0; j < m; j++) {
                int tmp = max(g[x][j] - (y - 1), 0);
                if (cur >= tmp) {
                    cur -= tmp;
                    g[x][j] -= tmp;
                }   else {
                    g[x][j] -= min(cur, tmp);
                    cur = 0;
                    break;
                }
            }
        }   else if (c == 'E') {
            for (int j = m - 1; j >= 0; j--) {
                int tmp = max(g[x][j] - (y - 1), 0);
                if (cur >= tmp) {
                    cur -= tmp;
                    g[x][j] -= tmp;
                }   else {
                    g[x][j] -= min(cur, tmp);
                    cur = 0;
                    break;
                }
            }
        }   else if (c == 'N') {
            for (int j = 0; j < n; j++) {
                int tmp = max(g[j][x] - (y - 1), 0);
                if (cur >= tmp) {
                    cur -= tmp;
                    g[j][x] -= tmp;
                }   else {
                    g[j][x] -= min(cur, tmp);
                    cur = 0;
                    break;
                }
            }
        }   else {
            for (int j = n - 1; j >= 0; j--) {
                int tmp = max(g[j][x] - (y - 1), 0);
                if (cur >= tmp) {
                    cur -= tmp;
                    g[j][x] -= tmp;
                }   else {
                    g[j][x] -= min(cur, tmp);
                    cur = 0;
                    break;
                }
            }
        }
    }
    int res = 0;
    for (int i = 0; i < n - p + 1; i++) {
        for (int j = 0; j < m - p + 1; j++) {
            int tmp = 0;
            for (int h = i; h < i + p; h++) {
                for (int l = j; l < j + p; l++) {
                    tmp += g[h][l];
                }
            }
            res = max(res, tmp);
        }
    }
    cout << res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Incorrect 6 ms 504 KB Output isn't correct
5 Incorrect 19 ms 1400 KB Output isn't correct
6 Incorrect 82 ms 5512 KB Output isn't correct
7 Execution timed out 2025 ms 10096 KB Time limit exceeded
8 Execution timed out 2058 ms 6512 KB Time limit exceeded
9 Execution timed out 2020 ms 6808 KB Time limit exceeded
10 Execution timed out 2027 ms 6872 KB Time limit exceeded
11 Execution timed out 2043 ms 6472 KB Time limit exceeded
12 Execution timed out 2045 ms 6864 KB Time limit exceeded
13 Execution timed out 2066 ms 10376 KB Time limit exceeded
14 Correct 843 ms 7456 KB Output is correct
15 Execution timed out 2044 ms 8156 KB Time limit exceeded
16 Execution timed out 2041 ms 6304 KB Time limit exceeded
17 Execution timed out 2070 ms 14600 KB Time limit exceeded
18 Execution timed out 2032 ms 10900 KB Time limit exceeded
19 Execution timed out 2041 ms 6500 KB Time limit exceeded
20 Execution timed out 2035 ms 8184 KB Time limit exceeded