Submission #716749

#TimeUsernameProblemLanguageResultExecution timeMemory
716749chenyanJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
5 ms864 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define ff first #define ss second #define all(x) x.begin(),x.end() #define pb push_back #define N 200010 int ans=1e9; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n,k,i,j,a,b,c,d,e,f,o; cin>>n>>k; string s; cin>>s; for(a=-1,b=-1,c=-1,d=-1,e=-1,f=-1,i=0,j=0,o=0;;){ while(b<n&&j<k){ if(s[++b]=='J')j++; } while(c<=b){ if(c>=0&&s[c]=='O')o--; c++; } while(d<n&&o<k){ if(s[++d]=='O')o++; } while(e<=d){ if(e>=0&&s[e]=='I')i--; e++; } while(f<n&&i<k){ if(s[++f]=='I')i++; } if(f==n)break; ans=min(f+d+b-e-c-a-3*k+3,ans); if(a>=0&&s[a]=='J')j--; a++; } cout<<(ans==1e9?-1:ans)<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...