Submission #924518

#TimeUsernameProblemLanguageResultExecution timeMemory
924518mochaJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; const int mx = 2e5+5; const int inf = 1e9+1; int n, k; string st; int main() { cin.tie(0);ios::sync_with_stdio(0); cin >> n >> k; cin >> st; int z, x, c, v, cj, co, ci; z = x = c = v = 0; cj = co = ci = 0; int ans = inf; while (z<n&&st[z]!='J') z++; x = z; while (x!=n&&cj<k) { if (st[x] == 'J') cj++; x++; } c = x; // cout << cj << " " << co << " " << ci << "\n"; while (c!=n&&co<k) { if (st[c] == 'O') co++; c++; } v = c; while (v!=n&&ci<k) { if (st[v] == 'I') ci++; v++; } // cout << z << " " << x << " " << c << " " << v << " " << cj << " " << co << " " << ci << "owo\n"; if (cj == k and co == k and ci == k) { ans = v-z-3*k; } else { cout << -1 << "\n"; return 0; } for (;x<n;) { while (z<n&&st[z]!='J') z++; cj--; while (x!=n&&cj<k) { if (st[x] == 'J') cj++; if (st[x] == 'O') co--; x++; } while (c!=n&&co<k) { if (st[c] == 'O') co++; if (st[c] == 'I') ci--; c++; } while (v!=n&&ci<k) { if (st[v] == 'I') ci++; v++; } if (cj == k and co == k and ci == k) { ans = min(ans,v-z-3*k); } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...