Submission #1115712

#TimeUsernameProblemLanguageResultExecution timeMemory
1115712staszic_ojuzJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
1 ms336 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 = 2){ int int_drug = J[ind]; if(int_drug != 0){ druga_dlugosc = min_dlug(int_drug, 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 < 0){ druga_dlugosc = 200001; } return max(-1, 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--){ //cout << J[i] << " " << I[i] << " " << O[i] << " " << word[i] << endl; 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); }

Compilation message (stderr)

ho_t2.cpp: In function 'int min_dlug(int, int)':
ho_t2.cpp:12:26: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   12 |             if(ind_pomoc = 2){
      |                ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...