# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
995497 | SuPythony | JJOOII 2 (JOI20_ho_t2) | C++17 | 0 ms | 428 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;
typedef long long ll;
int main() {
int n,k; cin>>n>>k;
string s; cin>>s;
vector<int> c(3,0);
for (char i: s) {
if (i=='J') c[0]++;
else if (i=='O') c[1]++;
else c[2]++;
}
if (c[0]<k||c[1]<k||c[2]<k) cout<<-1;
else {
int ans=0;
bool f=false;
int ind=0,c=0,prev=0;
while (ind<n&&c<k) {
if (s[ind]=='J') {
if (!f) {
f=true;
prev=ind;
} else {
ans+=ind-prev-1;
prev=ind;
}
c++;
}
ind++;
}
if (c==k&&ind<n) {
c=0;
f=false;
while (ind<n&&c<k) {
if (s[ind]=='O') {
if (!f) {
f=true;
prev=ind;
} else {
ans+=ind-prev-1;
prev=ind;
}
c++;
}
ind++;
}
if (c==k&&ind<n) {
c=0;
f=false;
while (ind<n&&c<k) {
if (s[ind]=='I') {
if (!f) {
f=true;
prev=ind;
} else {
ans+=ind-prev-1;
prev=ind;
}
c++;
}
ind++;
}
if (c==k) cout<<ans;
else cout<<-1;
} else cout<<-1;
} else cout<<-1;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |