이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 4e5 + 2;
int n;
string s;
vector<int> white, black;
bool cross(int x1, int y1, int x2, int y2){
if(x1 > y1) swap(x1, y1);
if(x2 > y2) swap(x2, y2);
if(x1 < x2 && y2 < y1) return false;
if(x2 < x1 && y1 < y2) return false;
if(x1 > y2 || x2 > y1) return false;
return true;
}
int calc(int delta){
int ret = 0;
for(int i = 0; i < n; ++i){
for(int j = i + 1; j < n; ++j){
if(cross(white[i], black[(i + delta + n) % n], white[j], black[(j + delta + n) % n])) ++ret;
}
}
return ret;
}
int main(){
cin >> n >> s;
for(int i = 0; i < 2*n; ++i){
if(s[i] == 'W') white.push_back(i);
else black.push_back(i);
}
int ans = 0;
for(int i = -1; i <= 1; ++i){
ans = max(ans, calc(n/2 + i));
}
cout << ans;
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... |