Submission #922911

#TimeUsernameProblemLanguageResultExecution timeMemory
922911viwlesxqJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
8 ms2460 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define size(x) (int)x.size() #define all(x) x.begin(), x.end() template<class S, class T> bool chmin(S &a, const T &b) { return a > b ? (a = b) == b : false; } template<class S, class T> bool chmax(S &a, const T &b) { return a < b ? (a = b) == b : false; } const int inf = 1e9 + 7; signed main() { cin.tie(nullptr)->sync_with_stdio(false); int n, k; cin >> n >> k; string s; cin >> s; s = '$' + s; int res = inf; deque<int> J, O, I; for (int i = 1; i <= n; ++i) { if (s[i] == 'O') O.push_back(i); else if (s[i] == 'I' && size(O) >= k) { I.push_back(i); } } for (int i = 1; i <= n; ++i) { if (s[i] == 'O' && size(J) >= k && size(O) >= k && size(I) >= k) { int cur = O[k - 1] - O[0] + 1 - k; cur += O[0] - J.back() - 1; cur += J.back() - J[size(J) - k] + 1 - k; cur += I[0] - O[k - 1] - 1; cur += I[k - 1] - I[0] + 1 - k; chmin(res, cur); } if (s[i] == 'J') J.push_back(i); else if (s[i] == 'O') { O.pop_front(); if (size(O) < k) break; while (!I.empty() && I.front() < O[k - 1]) I.pop_front(); } } cout << (res == inf ? -1 : res); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...