Submission #306839

#TimeUsernameProblemLanguageResultExecution timeMemory
306839MrDominoMonochrome Points (JOI20_monochrome)C++14
25 / 100
2072 ms404 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int N = (int) 2e5 + 7; int n; string s; vector<int> a; vector<int> b; int f(int l, int r, int x) { return (l <= x && x <= r); } ll get(int k) { vector<pair<int, int>> p; for (int i = 0; i < n; i++) { p.push_back({a[i], b[(i + k) % n]}); } for (auto &it : p) { if (it.second < it.first) { swap(it.first, it.second); } } sort(p.begin(), p.end()); ll sol = 0; for (int i = 0; i < (int) p.size(); i++) { for (int j = 0; j < i; j++) { sol += (p[i].first <= p[j].second && p[j].second <= p[i].second); } } return sol; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> s; for (int i = 0; i < 2 * n; i++) { if (s[i] == 'W') { a.push_back(i); } else { b.push_back(i); } } ll sol = 0; for (int k = 0; k < n; k++) { sol = max(sol, get(k)); } cout << sol << "\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...