Submission #1115698

#TimeUsernameProblemLanguageResultExecution timeMemory
1115698staszic_ojuzJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
1 ms464 KiB
#include <bits/stdc++.h> using namespace std; int n, k, J[200001], O[200001], I[200001]; string wzor, word; int min_dlug(int ind, int ind_pomoc){ int dlugosc = 0, druga_dlugosc = 200001; while(ind_pomoc < k * 3){ if(wzor[ind_pomoc] == 'J'){ dlugosc += J[ind] - ind - 1; if(ind_pomoc == k){ druga_dlugosc = min_dlug(ind, 1); } }else if(wzor[ind_pomoc] == 'O'){ dlugosc += O[ind] - ind - 1; }else if(wzor[ind_pomoc] == 'I'){ dlugosc += I[ind] - ind - 1; } if(ind_pomoc + 1 == k * 3){ ind = 200001; }else if(ind_pomoc + 1 > 2 * k){ ind = I[ind]; }else if(ind_pomoc + 1 > k){ ind = O[ind]; }else{ ind = J[ind]; } if(ind == 0){ return -1; } ind_pomoc++; } if(druga_dlugosc == -1){ druga_dlugosc = 200001; } return min(dlugosc, druga_dlugosc); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; cin >> word; for(int i = 0; i < k; i++){ wzor += "J"; } for(int i = 0; i < k; i++){ wzor += "O"; } for(int i = 0; i < k; i++){ wzor += "I"; } int index_1 = 200001; for(int i = n - 1; i > 0; i--){ J[i - 1] = J[i]; O[i - 1] = O[i]; I[i - 1] = I[i]; if(word[i] == 'J'){ index_1 = min(index_1, i); J[i - 1] = i; } if(word[i] == 'O'){ O[i - 1] = i; } if(word[i] == 'I'){ I[i - 1] = i; } } if(word[0] == 'J'){ index_1 = 0; } cout << min_dlug(index_1, 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...