Submission #427959

# Submission time Handle Problem Language Result Execution time Memory
427959 2021-06-15T06:07:32 Z cfalas Monochrome Points (JOI20_monochrome) C++14
35 / 100
2000 ms 24080 KB
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

int t, n;
vi a, b;

int dist(int a, int b){
	return min(abs(a-b), abs(a-b+n));
}

int bp[400000];
int wp[400000];
int br(int l, int r){
	if(l>r) return 0;
	if(l==0) return bp[r];
	else return bp[r] - bp[l-1];
}
int wr(int l, int r){
	if(l>r) return 0;
	if(l==0) return wp[r];
	else return wp[r] - wp[l-1];
}

int main(){
	cin>>n;
	string s;
	cin>>s;
	n*=2;
	set<int> w, b;
	bp[0] = (s[0]=='B');
	FORi(i,1,n){
		bp[i] = bp[i-1];
		if(s[i]=='B') bp[i]++;
	}
	wp[0] = (s[0]=='W');
	FORi(i,1,n){
		wp[i] = wp[i-1];
		if(s[i]=='W') wp[i]++;
	}
	FOR(i,n){
		if(s[i]=='W') w.insert(i);
		else b.insert(i);
	}

	vi c(n);
	int bans=0;
	FORi(off,0, n/2+1){
		auto it = b.begin();
		FOR(i,off) it++;
		int ans=0;
		FOA(v,w){
			c[v] = *it;
			c[*it] = v;
			//cout<<v<<" "<<*it<<endl;
			// ans = min(b in range + w in other side, w in range + b in other side)
			int mi = min(v, *it);
			int ma = max(v, *it);
			ans += min(br(mi+1,ma-1) , (wr(0,mi-1) + wr(ma+1,n-1))) + min(br(0,mi-1) + br(ma+1,n-1) , (wr(mi+1,ma-1)));
			//cout<<v<<" "<<*it<<" "<<ans<<endl;

			it++;
			if(it==b.end()) it = b.begin();
		}
		//cout<<ans<<endl;
		/*
		FOR(i,n){
			if(s[i]=='B')
			FORi(j,min(i,c[i])+1, max(i,c[i])){
				if(c[j]>max(i,c[i]) || c[j]<min(i,c[i])) ans++;
			}
		}*/
		bans = max(bans, ans);
	}
	cout<<bans/2<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 216 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 216 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 4 ms 332 KB Output is correct
34 Correct 99 ms 524 KB Output is correct
35 Correct 90 ms 524 KB Output is correct
36 Correct 85 ms 528 KB Output is correct
37 Correct 81 ms 460 KB Output is correct
38 Correct 74 ms 512 KB Output is correct
39 Correct 96 ms 520 KB Output is correct
40 Correct 72 ms 460 KB Output is correct
41 Correct 69 ms 488 KB Output is correct
42 Correct 88 ms 460 KB Output is correct
43 Correct 86 ms 524 KB Output is correct
44 Correct 77 ms 460 KB Output is correct
45 Correct 79 ms 460 KB Output is correct
46 Correct 84 ms 460 KB Output is correct
47 Correct 81 ms 460 KB Output is correct
48 Correct 91 ms 528 KB Output is correct
49 Correct 72 ms 580 KB Output is correct
50 Correct 82 ms 540 KB Output is correct
51 Correct 81 ms 460 KB Output is correct
52 Correct 94 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 216 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 4 ms 332 KB Output is correct
34 Correct 99 ms 524 KB Output is correct
35 Correct 90 ms 524 KB Output is correct
36 Correct 85 ms 528 KB Output is correct
37 Correct 81 ms 460 KB Output is correct
38 Correct 74 ms 512 KB Output is correct
39 Correct 96 ms 520 KB Output is correct
40 Correct 72 ms 460 KB Output is correct
41 Correct 69 ms 488 KB Output is correct
42 Correct 88 ms 460 KB Output is correct
43 Correct 86 ms 524 KB Output is correct
44 Correct 77 ms 460 KB Output is correct
45 Correct 79 ms 460 KB Output is correct
46 Correct 84 ms 460 KB Output is correct
47 Correct 81 ms 460 KB Output is correct
48 Correct 91 ms 528 KB Output is correct
49 Correct 72 ms 580 KB Output is correct
50 Correct 82 ms 540 KB Output is correct
51 Correct 81 ms 460 KB Output is correct
52 Correct 94 ms 460 KB Output is correct
53 Execution timed out 2075 ms 24080 KB Time limit exceeded
54 Halted 0 ms 0 KB -