답안 #988495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988495 2024-05-25T04:02:57 Z _callmelucian JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
47 ms 2132 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

vector<int> J, O, I;
int level;

bool ok (int l, int r) {
    int curJ = lower_bound(all(J), l) - J.begin();
    if (curJ + level > J.size()) return 0;
    int curO = lower_bound(all(O), J[curJ + level - 1]) - O.begin();
    if (curO + level > O.size()) return 0;
    int curI = lower_bound(all(I), O[curO + level - 1]) - I.begin();
    if (curI + level > I.size()) return 0;
    return I[curI + level - 1] <= r;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n >> level;
    string s; cin >> s;

    for (int i = 1; i <= n; i++) {
        if (s[i - 1] == 'J') J.push_back(i);
        if (s[i - 1] == 'O') O.push_back(i);
        if (s[i - 1] == 'I') I.push_back(i);
    }

    int ans = INT_MAX;
    for (int l = 1, r = 1; r <= n; r++) {
        while (l < r && ok(l + 1, r)) l++;
        if (ok(l, r))
            ans = min(ans, r - l + 1 - 3 * level);
    }
    cout << (ans == INT_MAX ? -1 : ans);

    return 0;
}

Compilation message

ho_t2.cpp: In function 'bool ok(int, int)':
ho_t2.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     if (curJ + level > J.size()) return 0;
      |         ~~~~~~~~~~~~~^~~~~~~~~~
ho_t2.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     if (curO + level > O.size()) return 0;
      |         ~~~~~~~~~~~~~^~~~~~~~~~
ho_t2.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     if (curI + level > I.size()) return 0;
      |         ~~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 43 ms 2016 KB Output is correct
37 Correct 44 ms 1948 KB Output is correct
38 Correct 47 ms 1968 KB Output is correct
39 Correct 39 ms 1992 KB Output is correct
40 Correct 33 ms 2016 KB Output is correct
41 Correct 43 ms 1956 KB Output is correct
42 Correct 42 ms 1832 KB Output is correct
43 Correct 15 ms 1400 KB Output is correct
44 Correct 16 ms 1496 KB Output is correct
45 Correct 21 ms 2016 KB Output is correct
46 Correct 21 ms 2004 KB Output is correct
47 Correct 21 ms 2016 KB Output is correct
48 Correct 23 ms 2016 KB Output is correct
49 Correct 16 ms 1472 KB Output is correct
50 Correct 23 ms 2004 KB Output is correct
51 Correct 23 ms 2016 KB Output is correct
52 Correct 14 ms 1632 KB Output is correct
53 Correct 19 ms 1748 KB Output is correct
54 Correct 24 ms 2132 KB Output is correct
55 Correct 26 ms 2020 KB Output is correct
56 Correct 14 ms 2016 KB Output is correct