# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
332695 | limabeans | JJOOII 2 (JOI20_ho_t2) | C++17 | 2092 ms | 3960 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 1e6 + 5;
int n,k;
string s;
int a[maxn];
int acc[maxn][3];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>k;
cin>>s;
for (int i=0; i<n; i++) {
if (s[i]=='J') {
a[i+1]=0;
} else if (s[i]=='O') {
a[i+1]=1;
} else if (s[i]=='I') {
a[i+1]=2;
} else assert(false);
}
for (int i=1; i<=n; i++) {
acc[i][a[i]]++;
for (int j=0; j<3; j++) {
acc[i][j] += acc[i-1][j];
}
}
auto qry = [&](int l, int r, int i) {
return acc[r][i] - acc[l-1][i];
};
vector<int> need = {k,k,k};
int res = 2*n;
for (int i=1; i<=n; i++) {
int rm = 0;
int x = 0;
need[0]=need[1]=need[2]=k;
for (int j=i; j<=n && x<3; j++) {
assert(x<3 && need[x]>0);
if (a[j]==x) {
need[x]--;
} else {
rm++;
}
while (x<3 && need[x]==0) x++;
}
if (x==3) {
res = min(res, rm);
}
}
if (res>n) res=-1;
cout<<res<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |