Submission #532530

#TimeUsernameProblemLanguageResultExecution timeMemory
532530amunduzbaevJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
14 ms4692 KiB
#include "bits/stdc++.h" using namespace std; #define ar array const int N = 2e5 + 5; int dp[3][N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n, k; cin>>n>>k; string s; cin>>s; vector<int> a(n); for(int i=0;i<n;i++){ if(s[i] == 'J') a[i] = 0; if(s[i] == 'O') a[i] = 1; if(s[i] == 'I') a[i] = 2; } memset(dp, -1, sizeof dp); for(int j=0;j<3;j++){ vector<int> p; for(int i=0;i<n;i++){ if(a[i] == j) p.push_back(i); } p.push_back(n); for(int l=k-1;l+1<(int)p.size();l++){ for(int i=p[l];i<p[l+1];i++) dp[j][i] = p[l-k+1]; } } int res = 1e9; for(int i=0;i<n;i++){ int l = i; for(int j=2;~j && l >= 0;j--){ l = dp[j][l]; if(j) l--; } if(l >= 0){ res = min(res, i - l + 1); } } if(res == 1e9) cout<<-1<<"\n"; else cout<<res - 3 * k<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...