답안 #201564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201564 2020-02-11T05:57:35 Z qkxwsm JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
13 ms 2684 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 200013;
const int INF = 1000000007;

int N, K;
int arr[MAXN];
vi pos[3];
int ans = INF;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> K;
    string temps; cin >> temps;
    FOR(i, 0, N)
    {
        if (temps[i] == 'J') arr[i] = 0;
        if (temps[i] == 'O') arr[i] = 1;
        if (temps[i] == 'I') arr[i] = 2;
    }
    //when is it ok to start the I?
    //when is it ok to start the O?
    //when is it ok to start the J?
    FOR(i, 0, N)
    {
        pos[arr[i]].PB(i);
    }
    int it1 = 0, it2 = 0;
    for (int i = 0; i <= SZ(pos[0]) - K; i++)
    {
        while(it1 < SZ(pos[1]) && pos[1][it1] < pos[0][i + K - 1]) it1++;
        if (it1 + K - 1 >= SZ(pos[1])) break;
        while(it2 < SZ(pos[2]) && pos[2][it2] < pos[1][it1 + K - 1]) it2++;
        if (it2 + K - 1 >= SZ(pos[2])) break;
        int lo = pos[0][i], hi = pos[2][it2 + K - 1];
        ckmin(ans, hi - lo + 1 - 3 * K);
    }
    if (ans >= INF)
    {
        cout << "-1\n";
        return 0;
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 424 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 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 424 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 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 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 6 ms 376 KB Output is correct
20 Correct 6 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 5 ms 424 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 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 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 6 ms 376 KB Output is correct
20 Correct 6 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 12 ms 2172 KB Output is correct
37 Correct 13 ms 2496 KB Output is correct
38 Correct 12 ms 2668 KB Output is correct
39 Correct 13 ms 2556 KB Output is correct
40 Correct 11 ms 2524 KB Output is correct
41 Correct 12 ms 2668 KB Output is correct
42 Correct 13 ms 2428 KB Output is correct
43 Correct 8 ms 1752 KB Output is correct
44 Correct 9 ms 2028 KB Output is correct
45 Correct 10 ms 2556 KB Output is correct
46 Correct 11 ms 2552 KB Output is correct
47 Correct 10 ms 2684 KB Output is correct
48 Correct 10 ms 2684 KB Output is correct
49 Correct 8 ms 1668 KB Output is correct
50 Correct 10 ms 2428 KB Output is correct
51 Correct 11 ms 2556 KB Output is correct
52 Correct 11 ms 2112 KB Output is correct
53 Correct 10 ms 2500 KB Output is correct
54 Correct 9 ms 2556 KB Output is correct
55 Correct 9 ms 2684 KB Output is correct
56 Correct 10 ms 2676 KB Output is correct