답안 #208288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208288 2020-03-10T14:40:51 Z jzh JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
14 ms 4352 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,i,x,y,k,ans=LLONG_MAX;
    cin>>n>>k;
    string s;
    cin>>s;
    deque<ll>d;
    ll J[n],I[n];
    J[0]=-1;
    for (i=0;i<n;i++){
        if (i!=0)J[i]=J[i-1];
        if (s[i]=='J'){
            d.push_back(i);
            while (d.size()>k)d.pop_front();
            if (d.size()==k)J[i]=d.front();
        }
    }
    d.clear();
    I[n-1]=-1;
    for (i=n-1;i>=0;i--){
        if (i!=n-1)I[i]=I[i+1];
        if (s[i]=='I'){
            d.push_back(i);
            while (d.size()>k)d.pop_front();
            if (d.size()==k)I[i]=d.front();
        }
    }
    d.clear();
    for (i=0;i<n;i++){
        if (s[i]=='O'){
            d.push_back(i);
            while (d.size()>k)d.pop_front();
            if (d.size()==k&&I[i]!=-1&&J[d.front()]!=-1){
                ans=min(ans,I[i]-J[d.front()]+1-k*3);
            }
        }
    }
    if (ans==LLONG_MAX)cout<<"-1\n";
    else cout<<ans<<'\n';
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while (d.size()>k)d.pop_front();
                    ~~~~~~~~^~
ho_t2.cpp:19:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (d.size()==k)J[i]=d.front();
                 ~~~~~~~~^~~
ho_t2.cpp:28:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while (d.size()>k)d.pop_front();
                    ~~~~~~~~^~
ho_t2.cpp:29:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (d.size()==k)I[i]=d.front();
                 ~~~~~~~~^~~
ho_t2.cpp:36:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while (d.size()>k)d.pop_front();
                    ~~~~~~~~^~
ho_t2.cpp:37:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (d.size()==k&&I[i]!=-1&&J[d.front()]!=-1){
                 ~~~~~~~~^~~
ho_t2.cpp:7:12: warning: unused variable 'x' [-Wunused-variable]
     ll n,i,x,y,k,ans=LLONG_MAX;
            ^
ho_t2.cpp:7:14: warning: unused variable 'y' [-Wunused-variable]
     ll n,i,x,y,k,ans=LLONG_MAX;
              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 248 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 4 ms 248 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 248 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 4 ms 248 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 248 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 4 ms 248 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 13 ms 3588 KB Output is correct
37 Correct 13 ms 3844 KB Output is correct
38 Correct 13 ms 3844 KB Output is correct
39 Correct 12 ms 3716 KB Output is correct
40 Correct 12 ms 3844 KB Output is correct
41 Correct 13 ms 3712 KB Output is correct
42 Correct 14 ms 3716 KB Output is correct
43 Correct 9 ms 2552 KB Output is correct
44 Correct 11 ms 3072 KB Output is correct
45 Correct 12 ms 3844 KB Output is correct
46 Correct 13 ms 3972 KB Output is correct
47 Correct 12 ms 3844 KB Output is correct
48 Correct 13 ms 3844 KB Output is correct
49 Correct 10 ms 2688 KB Output is correct
50 Correct 12 ms 3848 KB Output is correct
51 Correct 12 ms 3844 KB Output is correct
52 Correct 13 ms 4100 KB Output is correct
53 Correct 12 ms 4228 KB Output is correct
54 Correct 10 ms 3716 KB Output is correct
55 Correct 9 ms 4100 KB Output is correct
56 Correct 10 ms 4352 KB Output is correct