Submission #171917

#TimeUsernameProblemLanguageResultExecution timeMemory
171917NightmarUFO (IZhO14_ufo)C++17
15 / 100
2 ms380 KiB
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <iomanip> #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define ppb pop_back #define ft first #define sd second #define read freopen("input.txt", "r", stdin) #define write freopen("output.txt", "w", stdout) #define files read; write using namespace std; typedef long long ll; typedef pair<int, int> pii; const int Z = (int)1e3 + 228; const int N = (int)1e5 + 228; const int INF = (int)1e9 + 228; const int MOD = (int)1e9 + 7; int n, m, r, k, p; ll get_pref(vector<vector<ll> >& pref, int x1, int y1, int x2, int y2) { return pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1]; } void solve1() { vector<vector<ll> > a(n + 1, vector<ll> (m + 1)); vector<vector<ll> > pref(n + 1, vector<ll> (m + 1)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; while (k--) { char c; int num, h, cnt = 0; cin >> c >> num >> h; if (c == 'N') { for (int i = 1; i <= n; i++) { if (cnt == r) break; if (a[i][num] >= h) { a[i][num]--; cnt++; } } } else if (c == 'S') { for (int i = n; i > 0; i--) { if (cnt == r) break; if (a[i][num] >= h) { a[i][num]--; cnt++; } } } else if (c == 'W') { for (int i = 1; i <= m; i++) { if (cnt == r) break; if (a[num][i] >= h) { a[num][i]--; cnt++; } } } else { for (int i = m; i > 0; i--) { if (cnt == r) break; if (a[num][i] >= h) { a[num][i]--; cnt++; } } } } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i][j]; ll ans = 0; for (int i = p; i <= n; i++) for (int j = p; j <= m; j++) ans = max(ans, get_pref(pref, i - p + 1, j - p + 1, i, j)); cout << ans; } int main() { SWS; //files; cin >> n >> m >> r >> k >> p; if (n * m <= 55000 && k <= 5555) solve1(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...