답안 #701567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701567 2023-02-21T13:28:51 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
17 ms 5820 KB
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back

using namespace std;

int32_t main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    queue<int>q,q2,q3;
    vector<pair<int,int>>v,v2,v3;
    for(int i=0;i<s.size();i++){
        if(s[i]=='J'){
            q.push(i);
            if(q.size()==k){
                v.pb({q.front(),i});
                q.pop();
            }
        }
        else if(s[i]=='O'){
            q2.push(i);
            if(q2.size()==k){
                v2.pb({q2.front(),i});
                q2.pop();
            }
        }
        else{
            q3.push(i);
            if(q3.size()==k){
                v3.pb({q3.front(),i});
                q3.pop();
            }
        }
    }
    int ans=INT_MAX;
    for(auto i:v){
        int l=0,r=v2.size()-1;
        while(l<=r){
            int mid=(l+r)/2;
            if(v2[mid].ff>i.ss)r=mid-1;
            else l=mid+1;
        }
        int x=l;
        if(x==v2.size())break;
        l=0,r=v3.size()-1;
        while(l<=r){
            int mid=(l+r)/2;
            if(v3[mid].ff>v2[x].ss)r=mid-1;
            else l=mid+1;
        }
        if(l==v3.size())break;
        ans=min(ans,n-3*k-i.ff-n+v3[l].ss+1);
    }
    if(ans==INT_MAX)cout<<"-1"<<endl;
    else cout<<ans<<endl;
}

Compilation message

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:18:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
ho_t2.cpp:21:24: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   21 |             if(q.size()==k){
      |                ~~~~~~~~^~~
ho_t2.cpp:28:25: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   28 |             if(q2.size()==k){
      |                ~~~~~~~~~^~~
ho_t2.cpp:35:25: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   35 |             if(q3.size()==k){
      |                ~~~~~~~~~^~~
ho_t2.cpp:50:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if(x==v2.size())break;
      |            ~^~~~~~~~~~~
ho_t2.cpp:57:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         if(l==v3.size())break;
      |            ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 296 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 296 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 15 ms 3732 KB Output is correct
37 Correct 17 ms 4932 KB Output is correct
38 Correct 17 ms 5032 KB Output is correct
39 Correct 14 ms 3908 KB Output is correct
40 Correct 10 ms 3656 KB Output is correct
41 Correct 13 ms 3904 KB Output is correct
42 Correct 16 ms 4952 KB Output is correct
43 Correct 6 ms 2384 KB Output is correct
44 Correct 8 ms 3248 KB Output is correct
45 Correct 9 ms 3676 KB Output is correct
46 Correct 10 ms 3560 KB Output is correct
47 Correct 9 ms 3668 KB Output is correct
48 Correct 9 ms 3648 KB Output is correct
49 Correct 6 ms 2512 KB Output is correct
50 Correct 12 ms 3644 KB Output is correct
51 Correct 9 ms 3476 KB Output is correct
52 Correct 7 ms 2660 KB Output is correct
53 Correct 8 ms 2768 KB Output is correct
54 Correct 12 ms 5820 KB Output is correct
55 Correct 8 ms 3284 KB Output is correct
56 Correct 7 ms 2376 KB Output is correct