답안 #502581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502581 2022-01-06T09:49:25 Z amunduzbaev Monochrome Points (JOI20_monochrome) C++14
100 / 100
1193 ms 10828 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

const int N = 4e5 + 5;

struct BIT{
	int tree[N];
	void add(int i, int v){ i++;
		for(;i<N;i+=(i&-i)) tree[i] += v;
	}
	
	int get(int i){ i++;
		int rr = 0;
		for(;i>0;i-=(i&-i)) rr += tree[i];
		return rr;
	}
	
	int get(int l, int r){
		return get(r) - get(l-1);
	}
}tree;

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	string s; cin>>s;
	ar<vector<int>, 2> p;
	for(int i=0;i<2*n;i++){
		p[s[i] == 'B'].push_back(i);
	}
	
	auto check = [&](int k){
		memset(tree.tree, 0, sizeof tree.tree);
		int res = 0;
		vector<ar<int, 2>> a(n);
		for(int i=0;i<n;i++){
			int j = (i + k) % n;
			a[i] = {p[0][i], p[1][j]};
			if(a[i][0] > a[i][1]) swap(a[i][0], a[i][1]);
		}
		
		sort(a.begin(), a.end());
		for(auto x : a){
			res += tree.get(x[0], x[1]);
			tree.add(x[1], 1);
		} return res;
	};
	
	int l = 0, r = n - 1;
	while(l < r){
		int m = (l + r) >> 1;
		if(check(m) < check(m + 1)) l = m + 1;
		else r = m;
	}
	
	cout<<check(l)<<"\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 4 ms 3460 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 3 ms 3404 KB Output is correct
17 Correct 5 ms 3456 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 4 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 5 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 3 ms 3404 KB Output is correct
28 Correct 3 ms 3404 KB Output is correct
29 Correct 4 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 4 ms 3460 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 3 ms 3404 KB Output is correct
17 Correct 5 ms 3456 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 4 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 5 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 3 ms 3404 KB Output is correct
28 Correct 3 ms 3404 KB Output is correct
29 Correct 4 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
34 Correct 8 ms 3532 KB Output is correct
35 Correct 8 ms 3524 KB Output is correct
36 Correct 10 ms 3532 KB Output is correct
37 Correct 9 ms 3404 KB Output is correct
38 Correct 8 ms 3532 KB Output is correct
39 Correct 8 ms 3404 KB Output is correct
40 Correct 7 ms 3404 KB Output is correct
41 Correct 7 ms 3404 KB Output is correct
42 Correct 8 ms 3536 KB Output is correct
43 Correct 8 ms 3404 KB Output is correct
44 Correct 8 ms 3532 KB Output is correct
45 Correct 7 ms 3404 KB Output is correct
46 Correct 8 ms 3528 KB Output is correct
47 Correct 7 ms 3404 KB Output is correct
48 Correct 7 ms 3532 KB Output is correct
49 Correct 6 ms 3404 KB Output is correct
50 Correct 9 ms 3404 KB Output is correct
51 Correct 7 ms 3532 KB Output is correct
52 Correct 11 ms 3532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 4 ms 3460 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 3 ms 3404 KB Output is correct
17 Correct 5 ms 3456 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 4 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 5 ms 3404 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 3 ms 3404 KB Output is correct
28 Correct 3 ms 3404 KB Output is correct
29 Correct 4 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
34 Correct 8 ms 3532 KB Output is correct
35 Correct 8 ms 3524 KB Output is correct
36 Correct 10 ms 3532 KB Output is correct
37 Correct 9 ms 3404 KB Output is correct
38 Correct 8 ms 3532 KB Output is correct
39 Correct 8 ms 3404 KB Output is correct
40 Correct 7 ms 3404 KB Output is correct
41 Correct 7 ms 3404 KB Output is correct
42 Correct 8 ms 3536 KB Output is correct
43 Correct 8 ms 3404 KB Output is correct
44 Correct 8 ms 3532 KB Output is correct
45 Correct 7 ms 3404 KB Output is correct
46 Correct 8 ms 3528 KB Output is correct
47 Correct 7 ms 3404 KB Output is correct
48 Correct 7 ms 3532 KB Output is correct
49 Correct 6 ms 3404 KB Output is correct
50 Correct 9 ms 3404 KB Output is correct
51 Correct 7 ms 3532 KB Output is correct
52 Correct 11 ms 3532 KB Output is correct
53 Correct 1095 ms 10600 KB Output is correct
54 Correct 1053 ms 10828 KB Output is correct
55 Correct 1085 ms 10508 KB Output is correct
56 Correct 1103 ms 10612 KB Output is correct
57 Correct 1114 ms 10320 KB Output is correct
58 Correct 873 ms 10604 KB Output is correct
59 Correct 959 ms 10572 KB Output is correct
60 Correct 1057 ms 10248 KB Output is correct
61 Correct 1128 ms 10408 KB Output is correct
62 Correct 1038 ms 10396 KB Output is correct
63 Correct 1150 ms 10644 KB Output is correct
64 Correct 847 ms 10256 KB Output is correct
65 Correct 1038 ms 9952 KB Output is correct
66 Correct 1027 ms 10192 KB Output is correct
67 Correct 1116 ms 10252 KB Output is correct
68 Correct 734 ms 9864 KB Output is correct
69 Correct 854 ms 10568 KB Output is correct
70 Correct 874 ms 9936 KB Output is correct
71 Correct 1177 ms 10632 KB Output is correct
72 Correct 680 ms 10592 KB Output is correct
73 Correct 1193 ms 10820 KB Output is correct