이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define mp make_pair
using namespace std;
void debug(){
cout << "\n";
}
template<class T, class ...U>
void debug(T a, U ...b){
cout << a << " "; debug(b...);
}
const int maxN = 200005;
int main(){
int n, k;
string s;
cin >> n >> k >> s;
deque<int> dqJ, dqO, dqI;
int prevJ[maxN], sufI[maxN];
loop(i,0,n){
prevJ[i] = -1;
sufI[i] = -1;
}
int ans = 2147483647;
// J
loop(i,0,n){
if(dqJ.size() < k){
if(s[i] == 'J'){
dqJ.pb(i);
}
}
else{
prevJ[i] = dqJ.front();
if(s[i] == 'J'){
dqJ.pop_front();
dqJ.pb(i);
}
}
}
// I
for(int i = n-1; i >= 0; i--){
if(dqI.size() < k){
if(s[i] == 'I'){
dqI.push_front(i);
}
}
else{
sufI[i] = dqI.back();
if(s[i] == 'I'){
dqI.pop_back();
dqI.push_front(i);
}
}
}
// O
loop(i,0,n){
if(dqO.size() < k){
if(s[i] == 'O'){
dqO.pb(i);
}
}
else{
if(s[i] == 'O'){
dqO.pop_front();
dqO.pb(i);
}
if(prevJ[dqO.front()] != -1 && sufI[dqO.back()] != -1){
ans = min(ans, sufI[dqO.back()] - prevJ[dqO.front()] + 1 - k * 3);
}
}
}
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:34:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
34 | if(dqJ.size() < k){
| ~~~~~~~~~~~^~~
ho_t2.cpp:49:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | if(dqI.size() < k){
| ~~~~~~~~~~~^~~
ho_t2.cpp:64:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
64 | if(dqO.size() < k){
| ~~~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |