Submission #774452

#TimeUsernameProblemLanguageResultExecution timeMemory
774452stefanneaguJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
12 ms2004 KiB
#include <iostream> #include <vector> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; vector<int> J, O, I; for(int i = 0; i < n; i ++) { if(s[i] == 'J') { J.push_back(i); } if(s[i] == 'O') { O.push_back(i); } if(s[i] == 'I') { I.push_back(i); } } int ans = 1e9; for(int i = 0; i < (int) J.size() - k + 1; i ++) { int pos_o = lower_bound(O.begin(), O.end(), J[i + k - 1]) - O.begin(); if(pos_o < (int) O.size() - k + 1) { int pos_i = lower_bound(I.begin(), I.end(), O[pos_o + k - 1]) - I.begin(); if(pos_i < (int) I.size() - k + 1) { int term = I[pos_i + k - 1]; ans = min(ans, term - J[i] + 1 - 3 * k); } } } if(ans == 1e9) { cout << -1; return 0; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...