이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define all_of(v) (v).begin(), (v).end()
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fi first
#define se second
const int MAXN = 200005;
//const LL INF = (LL) 1e9 + 8763;
//const LL MOD = (LL) 1e9 + 7;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, arr[MAXN];
vector<int> W, B;
LL check2(int d) {
	int res = 0;
	for (int i = 0; i < n; i++) {
		int mat1 = (i + d) % n;
		for (int j = 0; j < i; j++) {
			int mat2 = (j + d) % n;
			int l1 = W[i], r1 = B[mat1];
			int l2 = W[j], r2 = B[mat2];
			if (l1 > r1) swap(l1, r1);
			int in1 = (l1 <= l2 && l2 <= r1), in2 = (l1 <= r2 && r2 <= r1);
			res += (in1 != in2);
		}
	}
	return res;
}
void solve() {
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		char ch;
		cin >> ch;
		arr[i] = (ch == 'B');
		if (arr[i]) B.push_back(i);
		else W.push_back(i);
	}
	
	LL ans = 0;
//	for (int d = 0; d < n; d++) {
//		ans = max(ans, check(d));
//	}
	for (int d = 0; d < n; d++) {
		ans = max(ans, check2(d));
	}
	cout << ans << '\n';
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int tc = 1;
//	cin >> tc;
	for (int i = 1; i <= tc; i++) {
		solve();
	}
	return 0;
} 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |