Submission #230070

#TimeUsernameProblemLanguageResultExecution timeMemory
230070AMO5JJOOII 2 (JOI20_ho_t2)C++98
100 / 100
15 ms2052 KiB
// READ & UNDERSTAND // ll, int overflow, array bounds, memset(0) // special cases (n=1?), n+1 (1-index) // do smth instead of nothing & stay organized // WRITE STUFF DOWN #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define MOD 1000000007 typedef long long ll; typedef pair <int, int> ii; typedef pair <ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef long double ld; ll INF=LLONG_MAX; int const mxn=2e5+5; vi dp[3]; //JOI,pos int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); int n,k; string s; cin >> n >> k >> s; for(int i=0; i<n; i++){ if(s[i]=='J')dp[0].pb(i); else if(s[i]=='O')dp[1].pb(i); else dp[2].pb(i); } int ans=1e9; for(int i=0; i<(int)dp[0].size()-k+1; i++){ int posini = dp[0][i]; int posj = dp[0][i+k-1]; int poso = upper_bound(all(dp[1]),posj)-dp[1].begin(); if(poso==(int)dp[1].size())break; poso += k-1; if(poso>=(int)dp[1].size())break; poso = dp[1][poso]; int posi = upper_bound(all(dp[2]),poso)-dp[2].begin(); if(posi==(int)dp[2].size())break; posi += k-1; if(posi>=(int)dp[2].size())break; posi = dp[2][posi]; ans = min(ans, posi-posini+1-k*3); } if(ans==1e9)ans=-1; cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...