Submission #1115173

#TimeUsernameProblemLanguageResultExecution timeMemory
1115173staszic_ojuzJJOOII 2 (JOI20_ho_t2)C++17
13 / 100
2037 ms1248 KiB
#include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <vector> #include <stack> #include <string> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n, k; cin >> n >> k; string s; cin >> s; if(s.find_first_of('J') >= s.find_last_of('I')) { cout << -1; return 0; } s = s.substr(s.find_first_of('J'), s.find_last_of('I') - s.find_first_of('J') + 1); n = s.size(); ll mn = 1e10; for(int i = 0; i < n; i++) { char c = s[i]; if(c != 'J') continue; ll ileo = 0, ilej = 1, ilei = 0, usu = 0; for(int j = i+1; j < n; j++) { char z = s[j]; if(z == 'O') { if(ileo < k) { usu += ilei; ilei = 0; ileo++; } else { usu++; } } if(z == 'J') { if(ilej < k) { usu += ileo; usu += ilei; ileo = 0; ilei = 0; ilej++; } else { usu++; } } if(z == 'I') { if(ilei + 1 >= k && ilej >= k && ileo >= k) { ilei++; break; } else { ilei++; } } } if(ilei >= k && ileo >= k && ilej >= k) { mn = min(usu, mn); } } cout << (mn <= 2e8 ? mn : -1); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...