이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 200005;
ll loc, cnt;
vector <ll> locJ, locO, locI;
int main() {
scanf("%lld%lld", &n, &k);
scanf("%s", str);
s = 0;
for(ll i = 0; i < n; i++){
if(str[i]=='J')locJ.push_back(i);
else if(str[i]=='O')locO.push_back(i);
else locI.push_back(i);
}
for(ll i = 0; i < locJ.size()-k+1; i++){
ll num = 0;
bool ok = 1;
num+=locJ[i+k-1]-locJ[i]+1-k;
s = upper_bound(locO.begin(), locO.end(), locJ[i+k-1])-locO.begin();
// if(s<0) ok = 0;
if(ok){
for (ll j = 1; j < k; j++){
s = upper_bound(locO.begin(), locO.end(), locO[s])-locO.begin();
// if(s<0||!ok){
// ok = 0;
// break;
// }
}
if(locO[s]<locJ[i+k-1]) ok = 0;
if(ok){
num+=locO[s]-locJ[i+k-1]-k;
t = upper_bound(locI.begin(), locI.end(), locO[s])-locI.begin();
// if(t<0) ok = 0;
for (ll j = 1; j<k; j++){
t = upper_bound(locI.begin(), locI.end(), locI[t])-locI.begin();
// if(t<0||!ok) {
// ok = 0;
// break;
// }
}
if(locI[t]<locO[s])ok = 0;
if(ok) {
num+=locI[t]-locO[s]-k;
ans = min(num, ans);
}
}
}
}
if(ans<200000)
printf("%lld", ans);
else
printf("-1");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:23:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
23 | for(ll i = 0; i < locJ.size()-k+1; i++){
| ~~^~~~~~~~~~~~~~~~~
ho_t2.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%lld%lld", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | 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... |