# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
962375 | 2024-04-13T11:35:45 Z | 0npata | Monochrome Points (JOI20_monochrome) | C++17 | 1 ms | 348 KB |
#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; int li = (w[0]+n)%(2*n); int ri = (w[0]+n+1)%(2*n); while(s[li] != 'B') { li += 2*n-1; li %= 2*n; } while(s[ri] != 'B') { ri += 1; ri %= 2*n; } int lii = 0; int rii = 0; for(int i = 0; i<n; i++) { if(b[i] == li) lii = i; if(b[i] == ri) rii = i; } vec<int> cand{lii, rii}; for(int i : cand) { 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'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Incorrect | 0 ms | 348 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Incorrect | 0 ms | 348 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Incorrect | 0 ms | 348 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Incorrect | 0 ms | 348 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |