답안 #1114935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114935 2024-11-19T19:59:28 Z AdamGS JJOOII 2 (JOI20_ho_t2) C++17
13 / 100
9 ms 2648 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MAXN = 20007;
int J[MAXN];
int O[MAXN];
int I[MAXN];

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> vJ;
    vector<int> vO;
    vector<int> vI;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'J')
            vJ.push_back(i);
        if(s[i] == 'O')
            vO.push_back(i);
        if(s[i] == 'I')
            vI.push_back(i);
    }
    for(int i = 0; i < (int)vJ.size() - k + 1; ++i)
        J[vJ[i]] = vJ[i+k-1];
    for(int i = 0; i < (int)vO.size() - k + 1; ++i)
        O[vO[i]] = vO[i+k-1];
    for(int i = 0; i < (int)vI.size() - k + 1; ++i)
        I[vI[i]] = vI[i+k-1];
    int naso[n];
    int nasi[n];
    int oo = n;
    int ii = n;
    for(int i = n-1; i >= 0; --i)
    {
        naso[i] = oo;
        nasi[i] = ii;
        if(s[i] == 'O')
            oo = i;
        if(s[i] == 'I')
            ii = i;
    }
    int odp = MAXN;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] != 'J')
            continue;
        int a = J[i];
        if(k != 1 && a == 0) continue;
        int b = naso[a];
        if(b == n) continue;
        int c = O[b];
        if(c == 0) continue;
        int d = nasi[c];
        if(d == n) continue;
        int e = I[d];
        if(e == 0) continue;
        odp = min(odp, e-i+1);
    }
    if(odp == MAXN)
    {
        cout << "-1";
        return 0;
    }
    cout << odp - k*3;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 504 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 508 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 504 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 508 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Runtime error 9 ms 2648 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -