# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
800608 | Dan4Life | Monochrome Points (JOI20_monochrome) | C++17 | 177 ms | 5220 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = (int)4e3+10;
string s; int n, ans, tot, fen[N], st[N];
void upd(int x, int v){ for(; x<N; x+=x&-x) fen[x]+=v; }
int sum(int x){ int s=0; for(; x>0; x-=x&-x)s+=fen[x]; return s; }
int sum(int a, int b){ return (a<=b)*(sum(b)-sum(a-1)); }
int main()
{
cin >> n >> s; vector<int> v[2];
for(int i = 0; i < 2*n; i++) v[s[i]>'B'].push_back(i+1);
for(int k = 0; k < n; k++){ tot=0;
for(int i = 0; i < n; i++){
int a = v[0][i], b = v[1][(i+k)%n];
if(a>b) swap(a,b); st[a] = a; st[b]=a;
}
for(int i = 1; i <= 2*n; i++){
if(st[i]==i) upd(st[i],1);
else tot+=sum(st[i]+1,i), upd(st[i],-1);
}
ans = max(ans, tot);
}
cout << ans;
}
Compilation message (stderr)
# | 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... |