답안 #868637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868637 2023-11-01T04:14:52 Z imarn JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
9 ms 4176 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    int dpj[n];
    deque<int>dq;
    for(int i=0;i<n;i++){
        if(s[i]=='J')dq.push_back(i);
        while(!dq.empty()&&dq.size()>k)dq.pop_front();
        if(dq.size()==k)dpj[i]=i-dq.front()+1-k;
        else dpj[i]=-1;
    }
    int cnt=0;
    int idx=0;
    int dpo[n];
    int ro[n];
    for(int i=0;i<n;i++)ro[i]=-1;
    for(int i=0;i<n;i++){
        if(s[i]=='O')cnt++;
        while(cnt==k){
            if(s[idx]=='O')cnt--;
            ro[idx]=i,dpo[idx]=i-idx+1-k;idx++;
        }
    }
    int dpi[n];dq.clear();
    dpi[n+1];dpi[n]=-1;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='I')dq.push_back(i);
        while(!dq.empty()&&dq.size()>k)dq.pop_front();
        if(dq.size()==k)dpi[i]=dq.front()-i+1-k;
        else dpi[i]=-1;
    }int ans=1e9;
    for(int i=0;i<n-1;i++){
        if(dpj[i]!=-1&&ro[i+1]!=-1&&ro[i+1]+1<n&&dpi[ro[i+1]+1]!=-1)ans=min(ans,dpj[i]+dpo[i+1]+dpi[ro[i+1]+1]);
        //cout<<dpj[i]<<" "<<ro[i+1]<<" "<<dpi[ro[i+1]+1]<<"\n";
    }cout<<(ans==1e9?-1:ans);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:10:37: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   10 |         while(!dq.empty()&&dq.size()>k)dq.pop_front();
      |                            ~~~~~~~~~^~
ho_t2.cpp:11:21: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   11 |         if(dq.size()==k)dpj[i]=i-dq.front()+1-k;
      |            ~~~~~~~~~^~~
ho_t2.cpp:27:12: warning: statement has no effect [-Wunused-value]
   27 |     dpi[n+1];dpi[n]=-1;
      |     ~~~~~~~^
ho_t2.cpp:30:37: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |         while(!dq.empty()&&dq.size()>k)dq.pop_front();
      |                            ~~~~~~~~~^~
ho_t2.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |         if(dq.size()==k)dpi[i]=dq.front()-i+1-k;
      |            ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 596 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 596 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 8 ms 3816 KB Output is correct
37 Correct 9 ms 4032 KB Output is correct
38 Correct 9 ms 4076 KB Output is correct
39 Correct 9 ms 4056 KB Output is correct
40 Correct 8 ms 4076 KB Output is correct
41 Correct 9 ms 4076 KB Output is correct
42 Correct 9 ms 4076 KB Output is correct
43 Correct 5 ms 2540 KB Output is correct
44 Correct 8 ms 3252 KB Output is correct
45 Correct 8 ms 4076 KB Output is correct
46 Correct 9 ms 4076 KB Output is correct
47 Correct 8 ms 3980 KB Output is correct
48 Correct 8 ms 4072 KB Output is correct
49 Correct 7 ms 3052 KB Output is correct
50 Correct 8 ms 4064 KB Output is correct
51 Correct 8 ms 3936 KB Output is correct
52 Correct 7 ms 3820 KB Output is correct
53 Correct 7 ms 4076 KB Output is correct
54 Correct 6 ms 4076 KB Output is correct
55 Correct 6 ms 4076 KB Output is correct
56 Correct 6 ms 4176 KB Output is correct