Submission #996852

#TimeUsernameProblemLanguageResultExecution timeMemory
996852vako_pJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
771 ms57232 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int mxN = 3e5 + 5; ll n,k; string s; map<ll,map<char,ll>> p; ll find(char ch, ll i){ ll l = i - 1, r = n; while(r > l + 1){ ll mid = l + (r - l) / 2; if(i == 0){ if(p[mid][ch] >= k) r = mid; else l = mid; continue; } if(p[mid][ch] - p[i - 1][ch] >= k) r = mid; else l = mid; } return r; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k >> s; for(int i = 0; i < n; i++){ if(i != 0){ p[i]['J'] = p[i - 1]['J']; p[i]['O'] = p[i - 1]['O']; p[i]['I'] = p[i - 1]['I']; } p[i][s[i]]++; } ll ans = 1e9; for(int i = 0; i < n; i++){ if(s[i] == 'J'){ ll r = find('J', i); r = find('O', r); r = find('I', r); if(r == n) continue; ans = min(ans, r - i + 1 - 3 * k); } } if(ans == 1e9) cout << -1; else cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...