Submission #244881

#TimeUsernameProblemLanguageResultExecution timeMemory
244881maximath_1JJOOII 2 (JOI20_ho_t2)C++11
0 / 100
5 ms384 KiB
#include <bits/stdc++.h> using namespace std; int pref[200005][3], last[200005][3]; int n, k; string s; int main(){ cin >> n >> k >> s; for(int i = 0; i < n; i ++){ for(int j = 0; j < 3; j ++) pref[i + 1][j] = pref[i][j]; if(s[i] == 'J') pref[i + 1][0] ++; if(s[i] == 'O') pref[i + 1][1] ++; if(s[i] == 'I') pref[i + 1][2] ++; } int ans = 2e9, lf; lf = 0; for(int rg = 0; rg < n; rg ++){ for(;pref[rg + 1][0] - pref[lf][0] >= k; lf ++); last[rg][0] = lf - 1; } lf = 0; for(int rg = 0; rg < n; rg ++){ for(;pref[rg + 1][1] - pref[lf][1] >= k; lf ++); last[rg][1] = lf - 1; } lf = 0; for(int rg = 0; rg < n; rg ++){ for(;pref[rg + 1][2] - pref[lf][2] >= k; lf ++); last[rg][2] = lf - 1; } for(int i = 0; i < n; i ++){ int nw = last[i][2] - 1; if(nw >= 0) nw = last[nw][1] - 1; else nw = -3; if(nw >= 0) nw = last[nw][0] - 1; else nw = -3; if(nw != -3) ans = min(ans, i - nw); } if(ans == 2e9) cout << -1 << endl; else cout << ans - 3 * k << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...