Submission #1094150

#TimeUsernameProblemLanguageResultExecution timeMemory
1094150thangdz2k7Monochrome Points (JOI20_monochrome)C++17
100 / 100
14 ms4624 KiB
// author : thembululquaUwU // 3.9.2024 #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define endl '\n' using namespace std; using ll = long long; using ii = pair <int, int>; using vi = vector <int>; const int N = 4e5 + 5; const int mod = 1e9 + 7; void maxl(auto &a, auto b) {a = max(a, b);} void minl(auto &a, auto b) {a = min(a, b);} int n; string s; void solve(){ cin >> n; cin >> s; vi black, white; for (int i = 0; i < 2 * n; ++ i) if (s[i] == 'B') black.pb(i); else white.pb(i); vector <ll> pref(n); auto update = [&](int l, int r, int x){ if (l >= r) return; if (l < 0) l += n, r += n; if (r > n) r -= n; pref[l] += x; if (r < n) pref[r] -= x; if (l >= r) pref[0] += x; }; int j = 0, k = 0, l = 0; for (int i = 0; i < n; ++ i){ while (j < n && white[j] - black[i] <= -n) ++ j; while (k < n && white[k] - black[i] <= 0) ++ k; while (l < n && white[l] - black[i] <= n) ++ l; update(-i, j - i, n + n - black[i]); update(j - i, k - i, black[i]); update(k - i, l - i, -black[i]); update(l - i, n - i, n + n + black[i]); } j = k = l = -1; for (int i = 0; i < n; ++ i){ while (j + 1 < n && white[i] - black[j + 1] > n) ++ j; while (k + 1 < n && white[i] - black[k + 1] > 0) ++ k; while (l + 1 < n && white[i] - black[l + 1] > -n) ++ l; update(i - n + 1, i - l, white[i]); update(i - l, i - k, -white[i]); update(i - k, i - j, white[i]); update(i - j, i + 1, -white[i]); } #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fd(sr, x) (lower_bound(sr.begin(), sr.end(), x) - sr.begin()) #define uq(sr) (sr).erase(unique(all((sr))), (sr).end()) #define szv(v) (int((v).size())) partial_sum(all(pref), pref.begin()); cout << (*max_element(all(pref)) - n) / 2; } int main(){ if (fopen("pqh.inp", "r")){ freopen("pqh.inp", "r", stdin); freopen("pqh.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t --) solve(); return 0; }

Compilation message (stderr)

monochrome.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
monochrome.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
monochrome.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
monochrome.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
monochrome.cpp: In function 'int main()':
monochrome.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
monochrome.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...