Submission #171971

# Submission time Handle Problem Language Result Execution time Memory
171971 2019-12-30T17:37:18 Z Nightmar UFO (IZhO14_ufo) C++17
55 / 100
1244 ms 191320 KB
#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;

vector<vector<int> > a;
vector<vector<ll> > pref;
vector<vector<int> > t_row, t_col;

void build_row(int ind, int v, int tl, int tr)
{
	if (tl == tr)
	{
		t_row[ind][v] = a[ind][tl];
		return; 
	}
	int mid = (tl + tr) / 2;
	build_row(ind, 2 * v, tl, mid);
	build_row(ind, 2 * v + 1, mid + 1, tr);
	t_row[ind][v] = max(t_row[ind][2 * v], t_row[ind][2 * v + 1]);
}

void build_col(int ind, int v, int tl, int tr)
{
	if (tl == tr)
	{
		t_col[ind][v] = a[tl][ind];
		return;
	}
	int mid = (tl + tr) / 2;
	build_col(ind, 2 * v, tl, mid);
	build_col(ind, 2 * v + 1, mid + 1, tr);
	t_col[ind][v] = max(t_col[ind][2 * v], t_col[ind][2 * v + 1]);
}

void update_row(int ind, int v, int tl, int tr, int pos)
{
	if (tl == tr)
	{
		t_row[ind][v] = max(t_row[ind][v] - 1, 0);
		return;
	}
	int mid = (tl + tr) / 2;
	if (pos <= mid) update_row(ind, 2 * v, tl, mid, pos);
	else update_row(ind, 2 * v + 1, mid + 1, tr, pos);
	t_row[ind][v] = max(t_row[ind][2 * v], t_row[ind][2 * v + 1]);
}

void update_col(int ind, int v, int tl, int tr, int pos)
{
	if (tl == tr)
	{
		t_col[ind][v] = max(t_col[ind][v] - 1, 0);
		return;
	}
	int mid = (tl + tr) / 2;
	if (pos <= mid) update_col(ind, 2 * v, tl, mid, pos);
	else update_col(ind, 2 * v + 1, mid + 1, tr, pos);
	t_col[ind][v] = max(t_col[ind][2 * v], t_col[ind][2 * v + 1]); 
}

int get_up(int ind, int v, int tl, int tr, int h)
{
	if (tl == tr)
		return tl;
	int mid = (tl + tr) / 2;
	if (t_col[ind][2 * v] >= h) return get_up(ind, 2 * v, tl, mid, h);
	else return get_up(ind, 2 * v + 1, mid + 1, tr, h);
}

int get_down(int ind, int v, int tl, int tr, int h)
{
	if (tl == tr)
		return tl;
	int mid = (tl + tr) / 2;
	if (t_col[ind][2 * v + 1] >= h) return get_down(ind, 2 * v + 1, mid + 1, tr, h);
	else return get_down(ind, 2 * v, tl, mid, h);
}

int get_left(int ind, int v, int tl, int tr, int h)
{
	if (tl == tr)
		return tl;
	int mid = (tl + tr) / 2;
	if (t_row[ind][2 * v] >= h) return get_left(ind, 2 * v, tl, mid, h);
	else return get_left(ind, 2 * v + 1, mid + 1, tr, h);
}

int get_right(int ind, int v, int tl, int tr, int h)
{
	if (tl == tr)
		return tl;
	int mid = (tl + tr) / 2;
	if (t_row[ind][2 * v + 1] >= h) return get_right(ind, 2 * v + 1, mid + 1, tr, h);
	else return get_right(ind, 2 * v, tl, mid, h);
}

ll get_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];
}

int main()
{
	SWS;
	//files;
	int n, m, r, k, p;
	cin >> n >> m >> r >> k >> p;
	a.resize(n + 1, vector<int> (m + 1, 0));
	pref.resize(n + 1, vector<ll> (m + 1, 0));
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	t_row.resize(n + 1, vector<int> (4 * (m + 5), 0));
	t_col.resize(m + 1, vector<int> (4 * (n + 5), 0));
	for (int i = 1; i <= n; i++)
		build_row(i, 1, 1, m);
	for (int i = 1; i <= m; i++)
		build_col(i, 1, 1, n);
	while (k--)
	{
		char c;
		int num, h;
		cin >> c >> num >> h;
		if (c == 'N')
		{
			for (int i = 1; i <= r; i++)
			{
				if (t_col[num][1] < h) break;
				int pos = get_up(num, 1, 1, n, h);
				a[pos][num]--;
				update_col(num, 1, 1, n, pos);
			}
		}
		else if (c == 'S')
		{
			for (int i = 1; i <= r; i++)
			{
				if (t_col[num][1] < h) break;
				int pos = get_down(num, 1, 1, n, h);
				a[pos][num]--;
				update_col(num, 1, 1, n, pos);
			}
		}
		else if (c == 'W')
		{
			for (int i = 1; i <= r; i++)
			{
				if (t_row[num][1] < h) break;
				int pos = get_left(num, 1, 1, m, h);
				a[num][pos]--;
				update_row(num, 1, 1, m, pos);
			}
		}
		else
		{
			for (int i = 1; i <= r; i++)
			{
				if (t_row[num][1] < h) break;
				int pos = get_right(num, 1, 1, m, h);
				a[num][pos]--;
				update_row(num, 1, 1, m, pos);
			}
		}
	}
	ll ans = 0;
	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];
	for (int i = p; i <= n; i++)
		for (int j = p; j <= m; j++)
			ans = max(ans, get_pref(i - p + 1, j - p + 1, i, j));
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 3 ms 504 KB Output isn't correct
4 Incorrect 13 ms 1016 KB Output isn't correct
5 Incorrect 71 ms 3960 KB Output isn't correct
6 Incorrect 160 ms 23700 KB Output isn't correct
7 Incorrect 273 ms 60868 KB Output isn't correct
8 Correct 227 ms 60612 KB Output is correct
9 Correct 484 ms 51672 KB Output is correct
10 Correct 644 ms 59972 KB Output is correct
11 Correct 465 ms 60960 KB Output is correct
12 Correct 665 ms 60184 KB Output is correct
13 Correct 800 ms 68856 KB Output is correct
14 Correct 565 ms 61472 KB Output is correct
15 Incorrect 638 ms 60568 KB Output isn't correct
16 Correct 274 ms 61728 KB Output is correct
17 Incorrect 849 ms 69848 KB Output isn't correct
18 Correct 264 ms 66816 KB Output is correct
19 Incorrect 425 ms 75020 KB Output isn't correct
20 Correct 1244 ms 191320 KB Output is correct