제출 #171925

#제출 시각아이디문제언어결과실행 시간메모리
171925NightmarUFO (IZhO14_ufo)C++17
20 / 100
6 ms632 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 (1LL * n * m * k <= 5e8) solve1();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...