Submission #652827

#TimeUsernameProblemLanguageResultExecution timeMemory
652827ghostwriterJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
32 ms3208 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat GOAT */ const int oo = 1e9; const int N = 2e5 + 1; int n, k, d[N][3], rs = oo; str s; #define getid(x) (x == 'J'? 0 : x == 'O'? 1 : 2) signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n >> k; cin >> s; s = "#" + s + "#"; FOR(i, 1, n) { FOR(j, 0, 2) d[i][j] = d[i - 1][j]; ++d[i][getid(s[i])]; } FOR(i, 1, n) { int l = 1, r = i, ans = -1, total = 0; WHILE(l <= r) { int mid = l + (r - l) / 2; if (d[i][2] - d[mid - 1][2] >= k) { ans = mid; l = mid + 1; } else r = mid - 1; } if (ans == -1) continue; total += i - ans + 1 - k; int pos = ans - 1; l = 1; r = pos; ans = -1; WHILE(l <= r) { int mid = l + (r - l) / 2; if (d[pos][1] - d[mid - 1][1] >= k) { ans = mid; l = mid + 1; } else r = mid - 1; } if (ans == -1) continue; total += pos - ans + 1 - k; pos = ans - 1; l = 1; r = pos; ans = -1; WHILE(l <= r) { int mid = l + (r - l) / 2; if (d[pos][0] - d[mid - 1][0] >= k) { ans = mid; l = mid + 1; } else r = mid - 1; } if (ans == -1) continue; total += pos - ans + 1 - k; rs = min(rs, total); } cout << (rs < oo? rs : -1); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t2.cpp:48:5: note: in expansion of macro 'FOR'
   48 |     FOR(i, 1, n) {
      |     ^~~
ho_t2.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t2.cpp:49:6: note: in expansion of macro 'FOR'
   49 |      FOR(j, 0, 2) d[i][j] = d[i - 1][j];
      |      ^~~
ho_t2.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ho_t2.cpp:52:5: note: in expansion of macro 'FOR'
   52 |     FOR(i, 1, n) {
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...