Submission #995497

#TimeUsernameProblemLanguageResultExecution timeMemory
995497SuPythonyJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
0 ms428 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n,k; cin>>n>>k; string s; cin>>s; vector<int> c(3,0); for (char i: s) { if (i=='J') c[0]++; else if (i=='O') c[1]++; else c[2]++; } if (c[0]<k||c[1]<k||c[2]<k) cout<<-1; else { int ans=0; bool f=false; int ind=0,c=0,prev=0; while (ind<n&&c<k) { if (s[ind]=='J') { if (!f) { f=true; prev=ind; } else { ans+=ind-prev-1; prev=ind; } c++; } ind++; } if (c==k&&ind<n) { c=0; f=false; while (ind<n&&c<k) { if (s[ind]=='O') { if (!f) { f=true; prev=ind; } else { ans+=ind-prev-1; prev=ind; } c++; } ind++; } if (c==k&&ind<n) { c=0; f=false; while (ind<n&&c<k) { if (s[ind]=='I') { if (!f) { f=true; prev=ind; } else { ans+=ind-prev-1; prev=ind; } c++; } ind++; } if (c==k) cout<<ans; else cout<<-1; } else cout<<-1; } else cout<<-1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...