Submission #297792

#TimeUsernameProblemLanguageResultExecution timeMemory
297792eriksuenderhaufMonochrome Points (JOI20_monochrome)C++11
35 / 100
2072 ms2836 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 5; int a[2*N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < 2*n; i++) a[i] = s[i] == 'B'; ll ans = 0; for (int i = 0; i < n; i++) { int ptr[2] = {i+n, i+n}, cnt[2] = {0, 0}, cntR[2] = {0, 0}; auto get = [&](int j) { return j < 2*n ? j : j-2*n; }; ll val = 0; for (int j = i; j < i+n; j++) { while (get(ptr[a[j]]) != i && a[get(ptr[a[j]])] == a[j]) cntR[a[j]]++, ptr[a[j]]++; ptr[a[j]]++; val += min(cntR[a[j]], cnt[a[j]^1]) + cnt[a[j]]++; } ans = max(ans, val); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...