Submission #963776

#TimeUsernameProblemLanguageResultExecution timeMemory
963776Akshat369JJOOII 2 (JOI20_ho_t2)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define vi vector<int> #define endl '\n' const int N = (int)1e5+5; void Solve(){ int n , k; cin>>n>>k; string s; cin>>s; deque<char> st; for(auto &i : s){ st.push_back(i); } while (!st.empty() and st.front()!='J'){ st.pop_front(); } while(!st.empty() and st.back() != 'I'){ st.pop_back(); } if(st.empty()){ cout<<-1<<endl; return; } s = " " + s; // cout<<s<<endl; int ans = 1e18; for(int i = 1 ; i <= n ; i++){ if (s[i]=='J'){ int temp = 0; int cntj = 1 , cnto = 0 , cnti = 0; int starto = -1 , starti = -1; //first index from where o starts for(int j = i +1 ; j<= n ; j++){ if (cntj<k and s[j]!='J'){ temp++; } if (s[j]=='J') cntj++; if (cntj==k){ starto = j; break; } } //cout<<"o"<<" "<<i<<" "<<starto << " " << temp <<endl; if (starto==-1) continue; for(int j = starto+1 ; j<= n ; j++){ if (cnto < k and s[j]!= 'O'){ temp++; } if (s[j]=='O') cnto++; if (cnto==k){ starti = j; break; } } //cout<<"i"<<" "<<i<< " "<<starti<<" "<<temp<<endl; if(starti==-1) continue; for(int j = starti+1; j <= n ; j++){ if (cnti < k and s[j]!='I'){ temp++; } if (s[j]=='I') cnti++; if (cnti==k){ break; } } if (cnti!=k) continue; // cout<<"last"<<" "<<i<< " "<<starti<<" "<<temp<<endl; ans = min(ans,temp); } } if (ans>=1e18){ cout<<-1<<endl; } else{ cout<<ans<<endl; } } int32_t main(){ Solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...