이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin>>n>>k;
string str;
cin>>str;
vector<int> vect(n, -1);
int nOfJ=0, s=0, e=0;
while (e<n){
if (str[e]=='J') nOfJ++;
if (nOfJ==k){
nOfJ--;
while (str[s]!='J') s++;
vect[s]=e;
s++;
}
e++;
}
s=0;
e=0;
int nOfO=0;
while (e<n){
if (str[e]=='O') nOfO++;
if (nOfO==k){
nOfO--;
while (str[s]!='O') s++;
vect[s]=e;
s++;
}
e++;
}
s=0;
e=0;
int nOfI=0;
while (e<n){
if (str[e]=='I') nOfI++;
if (nOfI==k){
nOfI--;
while (str[s]!='I') s++;
vect[s]=e;
s++;
}
e++;
}
int best=-1;
for (int i=0;i<n;i++){
if (str[i]!='J'||vect[i]==-1) continue;
int current;
bool found=false;
for (current=vect[i];current<n;current++){
if (str[current]=='O'&&vect[current]!=-1){
found=true;
current=vect[current];
break;
}
}
if (!found) continue;
found=false;
for (;current<n;current++){
if (str[current]=='I'&&vect[current]!=-1){
found=true;
current=vect[current];
break;
}
}
if (!found) continue;
best=max(best, current-i+1-3*k);
/*if (best<current-i+1-3*k){
cout<<i<<" "<<best<<" "<<current-i+1-3*k<<'\n';
best=current-i+1-3*k;
}*/
}
cout<<best<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |