Submission #940340

#TimeUsernameProblemLanguageResultExecution timeMemory
940340JakobZorzJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
6 ms3304 KiB
#include<iostream> #include<vector> #include<queue> #include<stack> #include<algorithm> #include<limits.h> #include<math.h> #include<map> #include<set> #include<unordered_map> #include<unordered_set> #include<iomanip> #include<cstring> #include<random> typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; int n,k; string str; int dpj[200001]; int dpo[200001]; int dpi[200001]; void fill(char c,int*dp){ dp[n]=n; int r=0; int cnt=k; while(r<n){ if(str[r]==c) cnt--; if(cnt==0) break; r++; } for(int l=0;l<n;l++){ if(l&&str[l-1]==c&&r!=n){ r++; while(r<n&&str[r]!=c) r++; } dp[l]=r; } } void solve(){ cin>>n>>k>>str; fill('J',dpj); fill('O',dpo); fill('I',dpi); /*for(int i=0;i<n;i++) cout<<dpj[i]<<" "; cout<<"\n"; for(int i=0;i<n;i++) cout<<dpo[i]<<" "; cout<<"\n"; for(int i=0;i<n;i++) cout<<dpi[i]<<" "; cout<<"\n";*/ int res=1e9; for(int i=0;i<n;i++){ int r=dpi[dpo[dpj[i]]]; //cout<<i<<" "<<r<<"\n"; if(r!=n){ res=min(res,r-i+1-3*k); } } if(res==1e9) res=-1; cout<<res<<"\n"; } int main(){ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL); //freopen("/Users/jakob/cp_testing/test.txt","r",stdin);freopen("output.out","w",stdout); int t=1;//cin>>t; while(t--)solve(); return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...