Submission #295432

# Submission time Handle Problem Language Result Execution time Memory
295432 2020-09-09T16:40:15 Z spdskatr Monochrome Points (JOI20_monochrome) C++14
35 / 100
290 ms 508 KB
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#define SZ (1<<12)

using namespace std;

int N;
int col[200005], sa[2005], sb[2005], ans, resa[2005], resb[2005];
vector<int> bws, bbs;

int inter(int a, int b) {
	int l1 = resa[a], r1 = resb[a];
	if (l1 > r1) swap(l1, r1);
	int l2 = resa[b], r2 = resb[b];
	if (l2 > r2) swap(l2, r2);
	//printf("inter [%d, %d] with [%d, %d]\n", l1, r1, l2, r2);
	return (l1 < l2 && l2 < r1 && r1 < r2) || (l1 > l2 && r2 > l1 && r1 > r2);
}

struct Segtree {
	int st[(1<<13)];
	void reset() {
		memset(st, 0, sizeof(st));
	}
	void seg_inc(int i, int v) {
		for (st[i += SZ] += v; i > 1; i >>= 1) st[i>>1] = st[i] + st[i^1];
	}
	int seg_q(int l, int r) {
		int res = 0;
		for (l += SZ, r += SZ; l < r; l >>= 1, r >>= 1) {
			if (l&1) res += st[l++];
			if (r&1) res += st[--r];
		}
		return res;
	}
} st1;

int main() {
	scanf("%d", &N);
	assert(N <= 2000);
	for (int i = 0; i < 2*N; i++) {
		char op;
		scanf(" %c", &op);
		if (op == 'B') col[i] = 1;
	}
	for (int i = 0; i < N; i++) {
		bws.clear();
		bbs.clear();
		st1.reset();
		for (int j = 0; j < N; j++) {
			sa[j] = col[i+j];
			sb[j] = col[(i+j+N)%(2*N)];
			if (sb[j]) bbs.push_back(j);
			else bws.push_back(j);
		}
		reverse(bws.begin(), bws.end());
		reverse(bbs.begin(), bbs.end());
		for (int j = 0; j < N; j++) {
			resa[j] = j;
			if (sa[j]) {
				resb[j] = bws.back();
				bws.pop_back();
			} else {
				resb[j] = bbs.back();
				bbs.pop_back();
			}
		}
		int cnt = 0;
		for (int j = 0; j < N; j++) {
			cnt += st1.seg_q(0, resb[j]);
			st1.seg_inc(resb[j], 1);
		}
		ans = max(ans, cnt);
	}
	printf("%d\n", ans);
}

Compilation message

monochrome.cpp: In function 'int main()':
monochrome.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
monochrome.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |   scanf(" %c", &op);
      |   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 290 ms 384 KB Output is correct
35 Correct 282 ms 504 KB Output is correct
36 Correct 275 ms 384 KB Output is correct
37 Correct 256 ms 384 KB Output is correct
38 Correct 205 ms 504 KB Output is correct
39 Correct 227 ms 384 KB Output is correct
40 Correct 188 ms 384 KB Output is correct
41 Correct 194 ms 384 KB Output is correct
42 Correct 271 ms 384 KB Output is correct
43 Correct 242 ms 384 KB Output is correct
44 Correct 226 ms 384 KB Output is correct
45 Correct 215 ms 384 KB Output is correct
46 Correct 232 ms 384 KB Output is correct
47 Correct 238 ms 384 KB Output is correct
48 Correct 233 ms 384 KB Output is correct
49 Correct 188 ms 384 KB Output is correct
50 Correct 231 ms 504 KB Output is correct
51 Correct 227 ms 508 KB Output is correct
52 Correct 230 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 290 ms 384 KB Output is correct
35 Correct 282 ms 504 KB Output is correct
36 Correct 275 ms 384 KB Output is correct
37 Correct 256 ms 384 KB Output is correct
38 Correct 205 ms 504 KB Output is correct
39 Correct 227 ms 384 KB Output is correct
40 Correct 188 ms 384 KB Output is correct
41 Correct 194 ms 384 KB Output is correct
42 Correct 271 ms 384 KB Output is correct
43 Correct 242 ms 384 KB Output is correct
44 Correct 226 ms 384 KB Output is correct
45 Correct 215 ms 384 KB Output is correct
46 Correct 232 ms 384 KB Output is correct
47 Correct 238 ms 384 KB Output is correct
48 Correct 233 ms 384 KB Output is correct
49 Correct 188 ms 384 KB Output is correct
50 Correct 231 ms 504 KB Output is correct
51 Correct 227 ms 508 KB Output is correct
52 Correct 230 ms 384 KB Output is correct
53 Runtime error 1 ms 384 KB Execution killed with signal 11
54 Halted 0 ms 0 KB -