Submission #683891

#TimeUsernameProblemLanguageResultExecution timeMemory
683891abc864197532Monochrome Points (JOI20_monochrome)C++17
35 / 100
2071 ms2376 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int,int> #define all(x) x.begin(), x.end() int main() { ios::sync_with_stdio(false), cin.tie(0); int n; string s; cin >> n >> s; vector <pii> a; for (int i = 0; i < n; ++i) { if (s[i] == s[i + n]) { a.emplace_back(i, s[i] == 'B' ? 1 : 0); } } int m = a.size(); ll ans = 1ll << 60; if (!m) { cout << 1ll * n * (n - 1) / 2 << '\n'; return 0; } for (int rt = 0; rt < m; ++rt) { vector <pii> stk; ll cur = 0; for (int i = 0; i < m; ++i) { auto [x, id] = a[(i + rt) % m]; if (!stk.empty() && stk.back().second != id) { int p = stk.back().first; stk.pop_back(); int len = abs(p - x); cur += min(len, n - len); } else { stk.emplace_back(x, id); } } ans = min(ans, cur); } cout << 1ll * n * (n - 1) / 2 - 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...