이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
const int N = 2e5 + 5;
int n;
int alb[N], neg[N], al, ng;
pair <int, int> muchie[N];
//bool idk4(int x, int a, int b)   {
//    if (a < b)
//        swap(a, b);
//    if (idk5() && x < b)
//        return true;
//    return false;
//}
int intersectie(int i,int j){
    int a=muchie[i].first;
    int b=muchie[i].second;
    int c=muchie[j].first;
    int d=muchie[j].second;
    if(a<b)
        swap(a,b);
    if((a>c and c>b) and (a>d and d>b))
        return false;
    if((a<d or d<b) and (a<c or c<b))
        return false;
    return 1;
//    if (idk4(a1, a2, b2) == idk4(b1, a2, b2))
//        return 0;
//    return 1;
}
int idk2(int a){
    if(a<=n)
        return a;
    a-=n;
    return a;
}
int idk(int x)  {
    for(int i=1;i<=n;i++){
        muchie[i]=make_pair(alb[i],neg[idk2(i+x-1)]);
    }
    int cnt = 0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            cnt+=intersectie(i,j);
        }
    }
//    cout<<cnt<<"\n";
    return cnt;
}
int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    char c;
    int a, ans = 0;
    for (int i = 1; i <= n + n; ++i)    {
        cin >> c;
        a = (c == 'B');
        if(a==0){
            alb[++al]=i;
        } else    {
            neg[++ng] = i;
        }
    }
    for (int i = max(1, n / 2 - 1); i <= min(n / 2 + 1, n); ++i)    {
        ans = max(ans, idk(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... |