Submission #1033317

#TimeUsernameProblemLanguageResultExecution timeMemory
1033317vjudge1JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
9 ms2156 KiB
#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]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); 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...