# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
917418 | atom | UFO (IZhO14_ufo) | C++17 | 2060 ms | 27740 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 "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
int n, m, rd, k, p;
vector <vector <int>> sh;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m >> rd >> k >> p;
sh.assign(n + 5, vector <int> (m + 5, 0));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> sh[i][j];
for (int _i = 1; _i <= k; ++_i) {
char cmd; int x, r, c, R, C, h;
cin >> cmd >> x >> h;
if (cmd == 'N') r = 1, c = x, R = n, C = x;
if (cmd == 'S') r = n, c = x, R = 1, C = x;
if (cmd == 'W') r = x, c = 1, R = x, C = m;
if (cmd == 'E') r = x, c = m, R = x, C = 1;
int cnt = rd;
if (cmd == 'N' || cmd == 'W') {
for (int i = r; i <= R; i++) {
for (int j = c; j <= C; ++j) {
if (sh[i][j] >= h && cnt > 0) {
sh[i][j]--;
cnt--;
}
}
}
}
else {
for (int i = r; i >= R; --i) {
for (int j = c; j >= C; --j) {
if (sh[i][j] >= h && cnt > 0) {
sh[i][j]--;
cnt--;
}
}
}
}
// debug(r, c, R, C, d, cnt);
}
// for (int i = 1; i <= n; ++i)
// for (int j = 1; j <= m; ++j)
// cout << sh[i][j] << " \n"[j == m];
vector <vector <ll>> prf(n + 5, vector <ll> (m + 5, 0));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
prf[i][j] = prf[i - 1][j] + prf[i][j - 1] - prf[i - 1][j - 1] + sh[i][j];
auto qry = [&] (int x, int y, int X, int Y) {
return prf[X][Y] + prf[x - 1][y - 1] - prf[X][y - 1] - prf[x - 1][Y];
};
ll ans = 0;
for (int r = 1; r + p - 1 <= n; ++r) {
for (int c = 1; c + p - 1 <= m; ++c) {
int R = r + p - 1; int C = c + p - 1;
ll sum = qry(r, c, R, C);
if (ans < sum) {
// debug(r, c, R, C);
ans = sum;
}
}
}
cout << ans << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |