# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
800608 | Dan4Life | Monochrome Points (JOI20_monochrome) | C++17 | 177 ms | 5220 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |