Submission #306840

#TimeUsernameProblemLanguageResultExecution timeMemory
306840MrDominoMonochrome Points (JOI20_monochrome)C++14
35 / 100
2064 ms8168 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 t[2 * N]; void clr() { for (int i = 1; i <= 2 * n; i++) { t[i] = 0; } } void add(int i, int x) { i++; while (i <= 2 * n) { t[i] += x; i += i & (-i); } } int sum(int i) { i++; int sol = 0; while (i) { sol += t[i]; i -= i & (-i); } return sol; } int sum(int i, int j) { return sum(j) - sum(i - 1); } 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; clr(); for (int i = 0; i < (int) p.size(); i++) { sol += sum(p[i].first, p[i].second); add(p[i].second, +1); } 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...