Submission #299662

#TimeUsernameProblemLanguageResultExecution timeMemory
299662dolijanJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,k; cin>>n>>k; string s; cin>>s; int a=0,b,c,d; while(s[a]!='J') { a++; if(a==n) return cout<<-1<<endl,0; } b=a; int numj=0; while(numj<k) { if(b==n) return cout<<-1<<endl,0; if(s[b]=='J') numj++; b++; } c=b; int numo=0; while(numo<k) { if(c==n) return cout<<-1<<endl,0; if(s[c]=='O') numo++; c++; } d=c; int numi=0; while(numi<k) { if(d==n) return cout<<-1<<endl,0; if(s[d]=='I') numi++; d++; } int kolko=0; for(int i=a;i<b;i++) if(s[i]!='J') kolko++; for(int i=b;i<c;i++) if(s[i]!='O') kolko++; for(int i=c;i<d;i++) if(s[i]!='I') kolko++; cout<<kolko<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...