답안 #427964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427964 2021-06-15T06:12:52 Z cfalas Monochrome Points (JOI20_monochrome) C++14
4 / 100
1 ms 332 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);
	}

	ll bans=0;
	FORi(off,max(n/4-10, 0), min(n/4+10, n/2+1)){
		auto it = b.begin();
		FOR(i,off) it++;
		ll ans=0;
		FOA(v,w){
			//cout<<v<<" "<<*it<<endl;
			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;
		bans = max(bans, ans);
	}
	cout<<bans/2<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 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 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 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 0 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 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 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 0 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 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 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 0 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 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Halted 0 ms 0 KB -