| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 962371 | 0npata | Monochrome Points (JOI20_monochrome) | C++17 | 105 ms | 556 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vec vector
#define pi pair<int, int>
#define fst first
#define snd second
#define pb push_back
int n;
string s;
int mes(vec<pi> p) {
int res = 0;
int j = p[0].fst;
int k = p[0].fst;
int cntw = 1;
int cntb = 0;
for(int i = 0; i<n; i++) {
while(k != p[i].fst) {
cntw -= s[k]=='W';
cntb -= s[k] == 'B';
k+=1;
k %= 2*n;
}
while(j != p[i].snd) {
j += 1;
j %= 2*n;
cntw += s[j]=='W';
cntb += s[j] == 'B';
}
int rw = cntw-1;
int orb = n-cntb;
res += min(rw, orb);
}
return res;
}
int32_t main() {
cin >> n;
cin >> s;
vec<int> b(0);
vec<int> w(0);
for(int i = 0; i<s.size(); i++) {
if(s[i] == 'W') {
w.pb(i);
}
else {
b.pb(i);
}
}
int ans = 0;
const int SQRTN = 600;
int cand = 0;
int mx = 0;
for(int i = 0; i<n; i+=SQRTN) {
// construct possible pairings
vec<pi> p;
for(int j = 0; j<n; j++) {
p.pb({w[j], b[(j+i)%n]});
}
int res = mes(p);
if(res > mx) cand = i;
}
for(int i = max(cand-SQRTN, -n); i<cand; i++) {
vec<pi> p;
for(int j = 0; j<n; j++) {
p.pb({w[j], b[(j+i+n)%n]});
}
int res = mes(p);
ans = max(res, ans);
}
for(int i = cand; i<cand+SQRTN; i++) {
vec<pi> p;
for(int j = 0; j<n; j++) {
p.pb({w[j], b[(j+i)%n]});
}
int res = mes(p);
ans = max(res, ans);
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (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... | ||||
