답안 #480093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480093 2021-10-14T14:48:36 Z 1bin 조개 줍기 (KOI17_shell) C++14
46 / 100
210 ms 50700 KB
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1505;
int n, k, dp[NMAX][NMAX], a[NMAX][NMAX], base = 1, ans, x, y, l, r, p;
vector<int> seg[NMAX];
char c;

void update(int y, int idx, int v) {
	idx += base;
	while (idx) {
		seg[y][idx] += v;
		idx /= 2;
	}
	return;
}

int find(int y, int l, int r) {
	int ret = dp[y][r];
	l += base; r += base;
	while (l <= r) {
		if (l & 1) ret += seg[y][l++];
		if (!(r & 1)) ret += seg[y][r--];
		l /= 2; r /= 2;
	}
	return ret;
}

int main(void) {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n;
	while (base < n + 2) base *= 2;
	for (int i = 0; i <= n; i++) seg[i].resize(base * 2);

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) cin >> a[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
			dp[i][j] += a[i][j];
			ans += dp[i][j];
		}

	cout << ans << '\n';
	for (int t = 0; t < n; t++) {
		cin >> c >> y >> x;
		l = r = x; 
		(c == 'U') ? p = 1 : p = -1;
		a[y][x] += p;
		for (int i = y; i <= n; i++) {
			if (i != y) {
				for (; l <= r; l++) {
					int b = find(i, 0, l);
					int now = max(find(i, 0, l - 1), find(i - 1, 0, l)) + a[i][l];
					if (b != now) break;
				}
			}
			if (l > r) break;
			update(i, l, p);
			for (; r + 1 <= n; r++) {
				int b = find(i, 0, r + 1) - p;
				int now = max(find(i, 0, r), find(i - 1, 0, r + 1)) + a[i][r + 1];
				if (now == b) break;
			}
			update(i, r + 1, -p);
			//cout << "L : " << l << "   R : " << r << '\n';
			ans += p * (r - l + 1);
		}
		cout << ans << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1356 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 3 ms 1296 KB Output is correct
4 Correct 3 ms 1260 KB Output is correct
5 Correct 4 ms 1264 KB Output is correct
6 Correct 3 ms 1356 KB Output is correct
7 Correct 2 ms 1356 KB Output is correct
8 Correct 2 ms 1260 KB Output is correct
9 Correct 2 ms 1228 KB Output is correct
10 Correct 2 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 46532 KB Output is correct
2 Correct 164 ms 46444 KB Output is correct
3 Correct 201 ms 46532 KB Output is correct
4 Correct 153 ms 46424 KB Output is correct
5 Correct 138 ms 46628 KB Output is correct
6 Correct 164 ms 46512 KB Output is correct
7 Correct 160 ms 46512 KB Output is correct
8 Correct 138 ms 46468 KB Output is correct
9 Correct 140 ms 46476 KB Output is correct
10 Correct 139 ms 46532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1356 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 3 ms 1296 KB Output is correct
4 Correct 3 ms 1260 KB Output is correct
5 Correct 4 ms 1264 KB Output is correct
6 Correct 3 ms 1356 KB Output is correct
7 Correct 2 ms 1356 KB Output is correct
8 Correct 2 ms 1260 KB Output is correct
9 Correct 2 ms 1228 KB Output is correct
10 Correct 188 ms 46532 KB Output is correct
11 Correct 164 ms 46444 KB Output is correct
12 Correct 201 ms 46532 KB Output is correct
13 Correct 153 ms 46424 KB Output is correct
14 Correct 138 ms 46628 KB Output is correct
15 Correct 164 ms 46512 KB Output is correct
16 Correct 160 ms 46512 KB Output is correct
17 Correct 138 ms 46468 KB Output is correct
18 Correct 140 ms 46476 KB Output is correct
19 Correct 139 ms 46532 KB Output is correct
20 Correct 2 ms 1356 KB Output is correct
21 Incorrect 210 ms 50700 KB Output isn't correct
22 Halted 0 ms 0 KB -