Submission #770705

#TimeUsernameProblemLanguageResultExecution timeMemory
770705JellyTheOctopusJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
8 ms3996 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second int N, K; string str; int main() { cin >> N >> K >> str; vector<int> J, O, I; for (int i = 0; i < (int)str.size(); i++) { if (str[i] == 'J') { J.push_back(i+1); } else if (str[i] == 'O') { O.push_back(i+1); } else { I.push_back(i+1); } } vector<pair<int, int>> A, B, C; for (int i = 0; i+K-1 < (int)J.size(); i++) { A.emplace_back(J[i], J[K+i-1]); } for (int i = 0; i+K-1 < (int)O.size(); i++) { B.emplace_back(O[i], O[K+i-1]); } for (int i = 0; i+K-1 < (int)I.size(); i++) { C.emplace_back(I[i], I[K+i-1]); } int a = 0; int b = 0; int c = 0; int ans = INT_MAX; while (a < (int)A.size() && b < (int)B.size() && c < (int)C.size()) { if (B[b].f < A[a].s) { b++; continue; } if (C[c].f < B[b].s) { c++; continue; } ans = min(ans, C[c].s-A[a].f-3*K+1); a++; } if (ans == INT_MAX) ans = -1; cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...