Submission #294155

# Submission time Handle Problem Language Result Execution time Memory
294155 2020-09-08T15:59:36 Z pit4h Monochrome Points (JOI20_monochrome) C++14
35 / 100
2000 ms 2836 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#ifndef LOCAL
#define cerr if(0)cerr
#endif
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
int n;
void inc(int& x) {
	x =  (x+1)%(2*n);	
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	string s; cin>>s;
	ll best = 0;
	for(int i=1; i<2*n; ++i) {
		if(s[i]==s[0]) continue;
		ll ans = 0;
		vector<bool> intersect(2*n, 1);
		int cnt = 1;
		vector<int> matched(2*n, -1);
		matched[0] = matched[i] = 0;
		int b = 1, w = i;			
		inc(w);	
		int iter = 1;
		while(iter<n) {
			while(s[b]!=s[0]) {
				if(matched[b] != -1) {
					intersect[matched[b]] = !intersect[matched[b]];
					if(intersect[matched[b]]) {
						cnt++;
					}
					else {
						cnt--;
					}
				}
				inc(b);
			}

			while(s[w]==s[0]) {
				if(matched[w] != -1) {
					intersect[w] = !intersect[w];
					if(intersect[w]) {
						cnt++;
					}
					else {
						cnt--;
					}
				}
				inc(w);
			}
			matched[b] = matched[w] = b;
			ans += cnt;
			cnt++;
			iter++;
			inc(b); inc(w);
		}
		best = max(best, ans);
	}
	cout<<best;
}
# 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 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 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 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 9 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 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 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 9 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 159 ms 412 KB Output is correct
35 Correct 167 ms 384 KB Output is correct
36 Correct 148 ms 408 KB Output is correct
37 Correct 154 ms 384 KB Output is correct
38 Correct 77 ms 384 KB Output is correct
39 Correct 87 ms 384 KB Output is correct
40 Correct 77 ms 384 KB Output is correct
41 Correct 81 ms 532 KB Output is correct
42 Correct 135 ms 384 KB Output is correct
43 Correct 78 ms 408 KB Output is correct
44 Correct 81 ms 416 KB Output is correct
45 Correct 92 ms 408 KB Output is correct
46 Correct 95 ms 504 KB Output is correct
47 Correct 92 ms 384 KB Output is correct
48 Correct 89 ms 384 KB Output is correct
49 Correct 74 ms 384 KB Output is correct
50 Correct 72 ms 504 KB Output is correct
51 Correct 69 ms 412 KB Output is correct
52 Correct 91 ms 404 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 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 9 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 159 ms 412 KB Output is correct
35 Correct 167 ms 384 KB Output is correct
36 Correct 148 ms 408 KB Output is correct
37 Correct 154 ms 384 KB Output is correct
38 Correct 77 ms 384 KB Output is correct
39 Correct 87 ms 384 KB Output is correct
40 Correct 77 ms 384 KB Output is correct
41 Correct 81 ms 532 KB Output is correct
42 Correct 135 ms 384 KB Output is correct
43 Correct 78 ms 408 KB Output is correct
44 Correct 81 ms 416 KB Output is correct
45 Correct 92 ms 408 KB Output is correct
46 Correct 95 ms 504 KB Output is correct
47 Correct 92 ms 384 KB Output is correct
48 Correct 89 ms 384 KB Output is correct
49 Correct 74 ms 384 KB Output is correct
50 Correct 72 ms 504 KB Output is correct
51 Correct 69 ms 412 KB Output is correct
52 Correct 91 ms 404 KB Output is correct
53 Execution timed out 2053 ms 2836 KB Time limit exceeded
54 Halted 0 ms 0 KB -