# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115736 | staszic_ojuz | JJOOII 2 (JOI20_ho_t2) | C++17 | 24 ms | 13056 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 <iostream>
#include <vector>
using namespace std;
int main()
{
int n,k;
string a;
cin >> n >> k >> a;
vector<vector<int>> pref(n,{0,0,0});
vector<int> J,O,I;
if (a[0]=='J'){
pref[0][0]++;
J.push_back(0);
}
else if (a[0]=='O'){
pref[0][1]++;
O.push_back(0);
}
else{
pref[0][2]++;
I.push_back(0);
}
int oski=-1;
for (int i=1; i<n; i++){
pref[i][0]=pref[i-1][0];
pref[i][1]=pref[i-1][1];
pref[i][2]=pref[i-1][2];
if (a[i]=='J'){
pref[i][0]++;
J.push_back(i);
}
else if (a[i]=='O'){
pref[i][1]++;
O.push_back(i);
}
else{
pref[i][2]++;
I.push_back(i);
}
}
/*for (int i:J) cout << i << ' ';
cout << '\n';
for (int i:O) cout << i << ' ';
cout << '\n';
for (int i:I) cout << i << ' ';
cout << '\n';*/
/*for (int j=0; j<3; j++){
for (int i=0; i<n; i++){
cout << pref[i][j] << ' ';
}
cout << '\n';
}*/
int wyn=1e9;
for (int i:J){
//cout << pref[i][0]+k-2 << ' ';
if (J.size()>pref[i][0]+k-2){
int aktj=J[pref[i][0]+k-2];
//cout << aktj << ' ' << pref[aktj][1]+k-2 << ' ';
if (O.size()>pref[aktj][1]+k-1){
int akto=O[k+pref[aktj][1]-1];
//cout << akto << ' ' << k+pref[akto][2]-1<< ' ';
if (I.size()>k+pref[akto][2]-1){
wyn=min(wyn,I[k+pref[akto][2]-1]-i-3*k+1);
}
}
}
//cout << '\n';
}
if (wyn==1e9) cout << -1;
else cout << wyn;
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... |