Submission #702266

#TimeUsernameProblemLanguageResultExecution timeMemory
702266Koful123JJOOII 2 (JOI20_ho_t2)C++17
1 / 100
1 ms1236 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define pb push_back #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() void solve(){ int n,k; cin >> n >> k; int ans = 1e18; string s; cin >> s; vector<array<int,26>> cnt(n + 37); cnt[0][s[0] - 'A'] = 1; for(int i = 1; i < n; i++){ for(int j = 0; j < 26; j++){ cnt[i][j] = cnt[i-1][j]; } cnt[i][s[i] - 'A']++; } auto check = [&](int i,int m,int ch){ return (cnt[i][ch] - (m > 0 ? cnt[m-1][ch] : 0) >= k); }; for(int i = 0; i < n; i++){ if(s[i] != 'I') continue; int l = 0,r = i; while(l < r){ int m = (l + r + 1) / 2; if(check(i,m,'I'-'A')) l = m; else r = m - 1; } if(!check(i,l,'I'-'A')) continue; int pre = l - 1; r = l - 1; l = 0; while(l < r){ int m = (l + r + 1) / 2; if(check(pre,m,'O'-'A')) l = m; else r = m - 1; } if(!check(pre,l,'O'-'A')) continue; pre = l - 1; r = l - 1; l = 0; while(l < r){ int m = (l + r + 1) / 2; if(check(pre,m,'J'-'A')) l = m; else r = m - 1; } if(!check(pre,l,'J'-'A')) continue; ans = min(ans,i-l+1 - k*3); } cout << (ans == 1e18 ? -1 : ans) << endl; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); 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...