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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#define jizz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
char str[200005];
ll s,t;
ll n, k;
ll ans = 0;
int main() {
scanf("%lld%lld", &n, &k);
scanf("%s", str);
s = 0;
t = n-1;
while(str[s]!='J') s++;
while(str[t]!='I') t--;
if(s<t){
ll loc = s;
ll cnt = 0;
// printf("J:");
for(loc = s; loc<=t; loc++){
if(str[loc] == 'J'){
// printf("%lld ", loc);
cnt++;
if(cnt == k){
ans += loc-s+1-k;
s = loc+1;
break;
}
}
}
// printf("\n");
if(cnt < k){
printf("-1");
}else{
cnt = 0;
// printf("I:");
for(loc = t; loc>=s; loc--){
if(str[loc] == 'I'){
// printf("%lld ", loc);
cnt++;
if(cnt == k){
ans += t-loc+1-k;
t = loc-1;
break;
}
}
}
// printf("\n");
if(cnt < k){
printf("-1");
}else{
cnt = 0;
// printf("O:");
for(loc = s; loc<=t; loc++){
if(str[loc] == 'O'){
// printf("%lld ", loc);
cnt++;
if(cnt == k){
break;
}
}
}
// printf("\n");
if(cnt < k){
printf("-1");
}else{
ans += t-s+1-k;
printf("%lld", ans);
}
}
}
}else{
printf("-1");
}
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%lld%lld", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%s", str);
| ~~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |