Submission #683928

#TimeUsernameProblemLanguageResultExecution timeMemory
683928abc864197532Monochrome Points (JOI20_monochrome)C++17
35 / 100
1901 ms3424 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() { srand(time(NULL)); ios::sync_with_stdio(false), cin.tie(0); double T = clock(); 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; } while ((clock() - T) / CLOCKS_PER_SEC <= 1.9) { int rt = rand() % m; 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...