Submission #300516

# Submission time Handle Problem Language Result Execution time Memory
300516 2020-09-17T08:29:36 Z mode149256 Monochrome Points (JOI20_monochrome) C++14
100 / 100
854 ms 9100 KB
/*input
16
WWWBWBBBBWWBWWBWWBBWWBBBWBBBWWBW
*/
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second

using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using pi = pair<int, int>;
using vpi = vector<pi>;
using str = string;

int N;
vi sk;
vi num;
vi R, B;

// k = [0; N/2)
ll kiek(int k) { // black i match with white i + k
	int cnt = 0;
	vi in(N, 0);

	vi other(N, -1);

	ll ret = 0;

	auto prN2 = [&](int a, int x) {
		return (a + x + (N / 2)) % (N / 2);
	};
	auto prN = [&](int a, int x) {
		return (a + x + N) % N;
	};

	for (int i = 0; i < N / 2; ++i)
	{
		// printf("i = %d, r = %d, B = %d\n", i, R[i], )
		other[R[i]] = B[prN2(i, k)];
		other[B[prN2(i, k)]] = R[i];
	}

	auto inv = [&](int a) {
		cnt -= (in[other[a]] ^ in[a]);
		in[a] ^= 1;
		cnt += (in[other[a]] ^ in[a]);
	};

	for (int i = R[0] + 1; i != B[k]; i = prN(i, 1))
	{
		inv(i);
	}

	// for (int i = 0; i < N; ++i) printf("%d %d\n", i+1, other[i]+1);
	int r = R[0];
	int b = B[k];
	for (int i = 0; i < N / 2; ++i)
	{
		while (r != R[i]) {
			r = prN(r, 1);
			// printf("r = %d\n", r);
			inv(r);
		}
		while (b != B[prN2(i, k)]) {
			// printf("b = %d\n", b);
			inv(b);
			b = prN(b, 1);
		}
		// printf("i = %d, R = %d, B = %d, cnt = %d\n", i, R[i], B[prN2(i, k)], cnt);
		ret += cnt;
		// inv(r);
		// 	printf("r = %d\n", r);
		// inv(b);
		// 	printf("b = %d\n", b);
	}
	return ret / 2;
}

int main() {
	cin >> N;
	N <<= 1;
	sk.resize(N);
	num.resize(N);
	{
		str s;
		cin >> s;
		for (int i = 0; i < N; ++i)
		{
			if (s[i] == 'W') {
				num[i] = (int)B.size();
				B.emplace_back(i);
			}
			else {
				num[i] = (int)R.size();
				R.emplace_back(i);
			}
			sk[i] = (s[i] == 'W');
		}
	}

	int l = 0;
	int h = N / 2 - 1;
	int m1, m2;

	while (h - l > 4) {
		int d = (h - l) / 3;
		m1 = l + d;
		m2 = h - d;

		if (kiek(m1) <= kiek(m2)) {
			l = m1;
		} else {
			h = m2 - 1;
		}
	}

	ll ats = 0;
	for (int i = l; i <= h; ++i)
	{
		ats = max(ats, kiek(i));
	}

	printf("%lld\n", ats);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 288 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 288 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 7 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 4 ms 512 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 4 ms 512 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 5 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 288 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 7 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 4 ms 512 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 4 ms 512 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 5 ms 416 KB Output is correct
53 Correct 831 ms 8968 KB Output is correct
54 Correct 854 ms 8956 KB Output is correct
55 Correct 791 ms 8296 KB Output is correct
56 Correct 825 ms 8588 KB Output is correct
57 Correct 564 ms 8584 KB Output is correct
58 Correct 594 ms 8712 KB Output is correct
59 Correct 577 ms 8644 KB Output is correct
60 Correct 579 ms 8732 KB Output is correct
61 Correct 598 ms 8708 KB Output is correct
62 Correct 598 ms 8720 KB Output is correct
63 Correct 640 ms 8596 KB Output is correct
64 Correct 522 ms 8516 KB Output is correct
65 Correct 559 ms 8224 KB Output is correct
66 Correct 595 ms 8224 KB Output is correct
67 Correct 593 ms 8264 KB Output is correct
68 Correct 568 ms 7976 KB Output is correct
69 Correct 588 ms 8712 KB Output is correct
70 Correct 554 ms 7972 KB Output is correct
71 Correct 530 ms 8768 KB Output is correct
72 Correct 521 ms 9100 KB Output is correct
73 Correct 600 ms 9012 KB Output is correct