Submission #1265769

#TimeUsernameProblemLanguageResultExecution timeMemory
1265769canhnam357JJOOII 2 (JOI20_ho_t2)C++20
100 / 100
4 ms1804 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; string s; cin >> n >> k >> s; vector<int> p[3]; for (int i = 0; i < n; i++) { if (s[i] == 'J') p[0].push_back(i); else if (s[i] == 'O') p[1].push_back(i); else p[2].push_back(i); } int ans = n, a = 0, b = 0; for (int i = k - 1; i < p[0].size(); i++) { while (a + k <= p[1].size() && p[1][a] < p[0][i]) a++; if (a + k > p[1].size()) break; while (b + k <= p[2].size() && p[2][b] < p[1][a + k - 1]) b++; if (b + k > p[2].size()) break; ans = min(ans, p[2][b + k - 1] - p[0][i - k + 1] + 1 - k * 3); } if (ans == n) ans = -1; cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...