# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
516577 | leinad2 | Monochrome Points (JOI20_monochrome) | C++17 | 1512 ms | 8056 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n, i, j, k, a, b;
long long ans=0;
char S[400010];
vector<int>A, B;
int tree[400010];
void init(){for(int i=1;i<=2*n;i++)tree[i]=0;}
void update(int pos, int v){while(pos<=2*n)tree[pos]+=v,pos+=(pos&-pos);}
int get(int pos){int res=0;while(pos)res+=tree[pos],pos-=(pos&-pos);return res;}
long long f(int i)
{
init();
vector<pair<int, int> >V;
for(int j=i;j<n;j++)V.push_back({A[j-i], B[j]});
for(int j=0;j<i;j++)V.push_back({A[j+n-i], B[j]});
for(auto &p:V)if(p.first>p.second)swap(p.first, p.second);
sort(V.begin(), V.end());
long long res=0;
for(auto p:V)
{
int a=p.second;
update(a, 1);
res+=get(a-1)-get(p.first);
}
ans=max(ans, res);
return res;
}
main()
{
scanf("%d", &n);
scanf("%s", &S);
for(i=0;i<2*n;i++)
{
if(S[i]=='B')A.push_back(i+1);
else B.push_back(i+1);
}
int a=0, b=n-1;
while(a+3<=b)
{
int m1=(a+a+b)/3, m2=(a+b+b)/3;
if(f(m1)>f(m2))b=m2;
else a=m1;
}
for(i=a;i<=b;i++)f(i);
cout<<ans;
}
컴파일 시 표준 에러 (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... |