# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1094149 | 2024-09-28T18:11:15 Z | thangdz2k7 | Monochrome Points (JOI20_monochrome) | C++17 | 1 ms | 348 KB |
// author : thembululquaUwU // 3.9.2024 #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define endl '\n' using namespace std; using ll = long long; using ii = pair <int, int>; using vi = vector <int>; const int N = 4e5 + 5; const int mod = 1e9 + 7; void maxl(auto &a, auto b) {a = max(a, b);} void minl(auto &a, auto b) {a = min(a, b);} int n; string s; void solve(){ cin >> n; cin >> s; vi black, white; for (int i = 0; i < 2 * n; ++ i) if (s[i] == 'B') black.pb(i); else white.pb(i); vector <ll> pref(n); auto update = [&](int l, int r, int x){ if (l >= r) return; if (l < 0) l += n, r += n; if (r > n) r -= n; pref[l] += x; if (r < n) pref[r] -= x; if (l >= r) pref[0] += x; }; int j = 0, k = 0, l = 0; for (int i = 0; i < n; ++ i){ while (j < n && white[j] - black[i] <= -n) ++ j; while (k < n && white[k] - black[i] <= 0) ++ k; while (l < n && white[l] - black[i] <= n) ++ l; update(-i, j - i, n + n - black[i]); update(j - i, k - i, black[i]); update(k - i, l - i, -black[i]); update(l - i, n - i, n + n + black[i]); } j = k = l = -1; for (int i = 0; i < n; ++ i){ while (j + 1 < n && white[i] - black[j + 1] > n) ++ j; while (k + 1 < n && white[i] - black[k + 1] > 0) ++ k; while (l + 1 < n && white[i] - black[k + 1] > -n) ++ l; update(i - n + 1, i - l, white[i]); update(i - l, i - k, -white[i]); update(i - k, i - j, white[i]); update(i - j, i + 1, -white[i]); } #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fd(sr, x) (lower_bound(sr.begin(), sr.end(), x) - sr.begin()) #define uq(sr) (sr).erase(unique(all((sr))), (sr).end()) #define szv(v) (int((v).size())) partial_sum(all(pref), pref.begin()); cout << (*max_element(all(pref)) - n) / 2; } int main(){ if (fopen("pqh.inp", "r")){ freopen("pqh.inp", "r", stdin); freopen("pqh.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t --) solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 348 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 348 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 348 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 348 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |