답안 #1115770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115770 2024-11-20T23:59:10 Z staszic_ojuz JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
8 ms 4556 KB
#include <bits/stdc++.h>
using namespace std;

int n, k, J[200001], O[200001], I[200001];
vector<int> J_gdzie, O_gdzie, I_gdzie;
string word;



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    cin >> word;
    if(word[0] == 'J'){
        J_gdzie.push_back(0);
        J[0]++;
    }
    if(word[0] == 'O'){
        O_gdzie.push_back(0);
        O[0]++;
    }
    if(word[0] == 'I'){
        I_gdzie.push_back(0);
        I[0]++;
    }

    for(int i = 1; i < n; i++){
        //cout << J[i] << " " << I[i] << " " << O[i] << " " << word[i] << endl;
        J[i] = J[i - 1];
        O[i] = O[i - 1];
        I[i] = I[i - 1];
        if(word[i] == 'J'){
            J_gdzie.push_back(i);
            J[i]++;
        }
        if(word[i] == 'O'){
            O_gdzie.push_back(i);
            O[i]++;
        }
        if(word[i] == 'I'){
            I_gdzie.push_back(i);
            I[i]++;
        }
    }
    for(int i = 0; i < n; i++){
        //cout << J[i] << " " << O[i] << " " << I[i] << endl;
    }
    int wynik = 200001;
    for(int i = 0; i < J_gdzie.size(); i++){
        int ind_j = J_gdzie[i];
        if(J_gdzie.size() - J[ind_j] + 2 > k){
            int ind_o = J_gdzie[J[ind_j] + k - 2];
            if(O_gdzie.size() - O[ind_o] + 1 > k){
                int ind_i = O_gdzie[O[ind_o] + k - 1];
                if(I_gdzie.size() - I[ind_i] + 1 > k){
                    wynik = min(wynik, I_gdzie[I[ind_i] + k - 1] - ind_j + 1 - 3 * k);
                }
            }
        }
    }
    if(wynik == 200001){
        wynik = -1;
    }
    cout << wynik;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0; i < J_gdzie.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
ho_t2.cpp:52:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |         if(J_gdzie.size() - J[ind_j] + 2 > k){
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
ho_t2.cpp:54:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |             if(O_gdzie.size() - O[ind_o] + 1 > k){
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
ho_t2.cpp:56:50: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |                 if(I_gdzie.size() - I[ind_i] + 1 > k){
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 1 ms 336 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 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 508 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 2 ms 336 KB Output is correct
3 Correct 1 ms 336 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 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 508 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 504 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 2 ms 336 KB Output is correct
27 Correct 1 ms 504 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 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 2 ms 336 KB Output is correct
3 Correct 1 ms 336 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 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 508 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 504 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 2 ms 336 KB Output is correct
27 Correct 1 ms 504 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 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 Correct 6 ms 3788 KB Output is correct
37 Correct 6 ms 4124 KB Output is correct
38 Correct 7 ms 4260 KB Output is correct
39 Correct 6 ms 4032 KB Output is correct
40 Correct 6 ms 4276 KB Output is correct
41 Correct 7 ms 4248 KB Output is correct
42 Correct 7 ms 4372 KB Output is correct
43 Correct 4 ms 2796 KB Output is correct
44 Correct 6 ms 3284 KB Output is correct
45 Correct 6 ms 4308 KB Output is correct
46 Correct 8 ms 4556 KB Output is correct
47 Correct 6 ms 4052 KB Output is correct
48 Correct 7 ms 4308 KB Output is correct
49 Correct 4 ms 2740 KB Output is correct
50 Correct 7 ms 4296 KB Output is correct
51 Correct 6 ms 4308 KB Output is correct
52 Correct 5 ms 3924 KB Output is correct
53 Correct 8 ms 4040 KB Output is correct
54 Correct 5 ms 4056 KB Output is correct
55 Correct 5 ms 4312 KB Output is correct
56 Correct 5 ms 4228 KB Output is correct