# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091991 | alex2407 | UFO (IZhO14_ufo) | C++17 | 2096 ms | 18460 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 <iostream>
#include <vector>
using namespace std;
vector<vector<long long> > a;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, r, k, p, hig, lin, cnt, maxi = 0;
string nav;
cin >> n >> m >> r >> k >> p;
a.resize(n);
for (int i = 0; i < n; i++) {
a[i].resize(m);
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < k; i++) {
cnt = r;
cin >> nav >> lin >> hig;
lin--;
if (nav == "S") {
for (int j = n - 1; j >= 0 && cnt; j--) {
if (a[j][lin] >= hig) {
a[j][lin]--;
cnt--;
}
}
}
if (nav == "N") {
for (int j = 0; j < n && cnt; j++) {
if (a[j][lin] >= hig) {
cnt--;
a[j][lin]--;
}
}
}
if (nav == "W") {
for (int j = 0; j < m && cnt; j++) {
if (a[lin][j] >= hig) {
a[lin][j]--;
cnt--;
}
}
}
if (nav == "E") {
for (int j = m - 1; j >= 0 && cnt; j--) {
if (a[lin][j] >= hig) {
cnt--;
a[lin][j]--;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!(i) && !(j)) {
continue;
} else if (!(i)) {
a[i][j] += a[i][j - 1];
} else if (!(j)) {
a[i][j] += a[i - 1][j];
} else {
a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
}
}
}
for (int i = p - 1; i < n; i++) {
for (int j = p - 1; j < m; j++) {
if (i == p - 1 && j == p - 1) {
maxi = max(maxi, a[i][j]);
} else if (i == p - 1) {
maxi = max(maxi, a[i][j] - a[i][j - p]);
} else if (j == p - 1) {
maxi = max(maxi, a[i][j] - a[i][j - p]);
} else {
maxi = max(maxi, a[i][j] - a[i - p][j] - a[i][j - p] + a[i - p][j - p]);
}
}
}
cout << maxi << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |