답안 #770689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770689 2023-07-01T17:48:55 Z JellyTheOctopus JJOOII 2 (JOI20_ho_t2) C++17
13 / 100
2000 ms 3572 KB
#include <bits/stdc++.h>
using namespace std;

int N, K;
string s;

int main() {
    cin >> N >> K >> s;
    vector<int> J, O, I;
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == 'J') J.push_back(i+1);
        else if (s[i] == 'O') O.push_back(i+1);
        else I.push_back(i+1);
    }
    O.push_back(INT_MAX);
    I.push_back(INT_MAX);
    int ans = INT_MAX;
    for (int i = 0; i+K-1 < (int)J.size(); i++) {
        int cur = 0;
        vector<int> arr;
        for (int j = i; j < i+K; j++) {
            if (!arr.empty()) cur += J[j]-arr.back()-1;
            arr.push_back(J[j]);
        }
        int u = upper_bound(O.begin(), O.end(), arr.back())-O.begin();
        if (u == INT_MAX) break;
        bool flag = false;
        for (int j = u; j < u+K; j++) {
            if (O[j] == INT_MAX) {
                flag = true;
                break;
            }
            cur += O[j]-arr.back()-1;
            arr.push_back(O[j]);
        }
        if (flag) break;
        u = upper_bound(I.begin(), I.end(), arr.back())-I.begin();
        if (u == INT_MAX) break;
        for (int j = u; j < u+K; j++) {
            if (I[j] == INT_MAX) {
                flag = true;
                break;
            }
            cur += I[j]-arr.back()-1;
            arr.push_back(I[j]);
        }
        if (flag) break;
        ans = min(ans, cur);
    }
    if (ans == INT_MAX) ans = -1;
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 0 ms 296 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 292 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 0 ms 296 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 292 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 16 ms 1476 KB Output is correct
37 Correct 15 ms 1820 KB Output is correct
38 Correct 18 ms 1964 KB Output is correct
39 Correct 1031 ms 1860 KB Output is correct
40 Correct 1971 ms 3084 KB Output is correct
41 Correct 1549 ms 1940 KB Output is correct
42 Correct 328 ms 1864 KB Output is correct
43 Correct 8 ms 1460 KB Output is correct
44 Correct 5 ms 1680 KB Output is correct
45 Correct 6 ms 2256 KB Output is correct
46 Correct 6 ms 2212 KB Output is correct
47 Correct 6 ms 2220 KB Output is correct
48 Correct 7 ms 2232 KB Output is correct
49 Correct 4 ms 1464 KB Output is correct
50 Correct 11 ms 2228 KB Output is correct
51 Correct 5 ms 2260 KB Output is correct
52 Correct 5 ms 1748 KB Output is correct
53 Correct 6 ms 2244 KB Output is correct
54 Correct 9 ms 1988 KB Output is correct
55 Execution timed out 2076 ms 3572 KB Time limit exceeded
56 Halted 0 ms 0 KB -