답안 #245418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245418 2020-07-06T11:27:04 Z egekabas JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
38 ms 1924 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<int, int>  pii;
typedef pair<ld, ld>  pld;
int n, k;
string s;
vector<int> v[3];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    //freopen("in.txt", "r", stdin);                                                                                             
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> k >> s;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'J')
            v[0].pb(i);
        else if(s[i] == 'O')
            v[1].pb(i);
        else
            v[2].pb(i);
    }
    int ans = 1e9;
    for(int i = 0; i < n; ++i){
        int cur = i;
        for(int j = 0; j < 3 && cur != 1e9; ++j){
            int idx = lower_bound(v[j].begin(), v[j].end(), cur)-v[j].begin();
            if(idx+k-1 < v[j].size())
                cur = v[j][idx+k-1]+1;
            else
                cur = 1e9;
        }
        //cout << i << ' ' << cur << '\n';
        if(cur != 1e9)
            ans = min(ans, cur-i-3*k);
        
    }
    if(ans == 1e9)
        cout << -1;
    else
        cout << ans;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:38:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(idx+k-1 < v[j].size())
                ~~~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 436 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 436 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 35 ms 1412 KB Output is correct
37 Correct 38 ms 1736 KB Output is correct
38 Correct 37 ms 1780 KB Output is correct
39 Correct 34 ms 1796 KB Output is correct
40 Correct 29 ms 1764 KB Output is correct
41 Correct 35 ms 1780 KB Output is correct
42 Correct 36 ms 1668 KB Output is correct
43 Correct 19 ms 1248 KB Output is correct
44 Correct 22 ms 1396 KB Output is correct
45 Correct 27 ms 1796 KB Output is correct
46 Correct 27 ms 1792 KB Output is correct
47 Correct 27 ms 1796 KB Output is correct
48 Correct 28 ms 1924 KB Output is correct
49 Correct 19 ms 1164 KB Output is correct
50 Correct 27 ms 1668 KB Output is correct
51 Correct 27 ms 1668 KB Output is correct
52 Correct 18 ms 1352 KB Output is correct
53 Correct 19 ms 1736 KB Output is correct
54 Correct 18 ms 1924 KB Output is correct
55 Correct 16 ms 1796 KB Output is correct
56 Correct 15 ms 1796 KB Output is correct