Submission #1115736

# Submission time Handle Problem Language Result Execution time Memory
1115736 2024-11-20T21:34:57 Z staszic_ojuz JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
24 ms 13056 KB
#include <iostream>                                                             
#include <vector>                                                               
using namespace std;                                                            
int main()                                                                      
{                                                                               
    int n,k;                                                                    
    string a;                                                                   
    cin >> n >> k >> a;                                                         
    vector<vector<int>> pref(n,{0,0,0});                                        
    vector<int> J,O,I;                                                          
    if (a[0]=='J'){                                                             
            pref[0][0]++;                                                       
            J.push_back(0);                                                     
        }                                                                       
        else if (a[0]=='O'){                                                    
            pref[0][1]++;                                                       
            O.push_back(0);                                                     
        }                                                                       
        else{                                                                   
            pref[0][2]++;                                                       
            I.push_back(0);                                                     
        }                                                                       
    int oski=-1;                                                                
    for (int i=1; i<n; i++){                                                    
        pref[i][0]=pref[i-1][0];                                                
        pref[i][1]=pref[i-1][1];                                                
        pref[i][2]=pref[i-1][2];                                                
        if (a[i]=='J'){                                                         
            pref[i][0]++;                                                       
            J.push_back(i);                                                     
        }                                                                       
        else if (a[i]=='O'){                                                    
            pref[i][1]++;                                                       
            O.push_back(i);                                                     
        }                                                                       
        else{                                                                   
            pref[i][2]++;                                                       
            I.push_back(i);                                                     
        }                                                                       
    }                                                                           
    /*for (int i:J) cout << i << ' ';                                           
    cout << '\n';                                                               
    for (int i:O) cout << i << ' ';                                             
    cout << '\n';                                                               
    for (int i:I) cout << i << ' ';                                             
    cout << '\n';*/                                                             
    /*for (int j=0; j<3; j++){                                                  
        for (int i=0; i<n; i++){                                                
            cout << pref[i][j] << ' ';                                          
        }                                                                       
        cout << '\n';                                                           
    }*/                                                                         
    int wyn=1e9;                                                                
    for (int i:J){                                                              
        //cout << pref[i][0]+k-2 << ' ';                                        
        if (J.size()>pref[i][0]+k-2){                                           
            int aktj=J[pref[i][0]+k-2];                                         
            //cout << aktj << ' ' << pref[aktj][1]+k-2 << ' ';                  
            if (O.size()>pref[aktj][1]+k-1){                                    
                int akto=O[k+pref[aktj][1]-1];                                  

                //cout << akto << ' ' << k+pref[akto][2]-1<< ' ';               
                if (I.size()>k+pref[akto][2]-1){                                
                    wyn=min(wyn,I[k+pref[akto][2]-1]-i-3*k+1);                  
                }                                                               
            }                                                                   
        }                                                                       
        //cout << '\n';                                                         
    }                                                                           
    if (wyn==1e9) cout << -1;                                                   
    else cout << wyn;                                                           
    return 0;                                                                   
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:56:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   56 |         if (J.size()>pref[i][0]+k-2){
      |             ~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:59:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   59 |             if (O.size()>pref[aktj][1]+k-1){
      |                 ~~~~~~~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:63:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |                 if (I.size()>k+pref[akto][2]-1){
      |                     ~~~~~~~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:23:9: warning: unused variable 'oski' [-Wunused-variable]
   23 |     int oski=-1;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 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 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 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 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 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 592 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 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 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 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 592 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 17 ms 11724 KB Output is correct
37 Correct 17 ms 12824 KB Output is correct
38 Correct 18 ms 12620 KB Output is correct
39 Correct 18 ms 12736 KB Output is correct
40 Correct 17 ms 12648 KB Output is correct
41 Correct 19 ms 13052 KB Output is correct
42 Correct 18 ms 13056 KB Output is correct
43 Correct 14 ms 7908 KB Output is correct
44 Correct 14 ms 9696 KB Output is correct
45 Correct 17 ms 12764 KB Output is correct
46 Correct 17 ms 12632 KB Output is correct
47 Correct 21 ms 12724 KB Output is correct
48 Correct 23 ms 12760 KB Output is correct
49 Correct 13 ms 8552 KB Output is correct
50 Correct 18 ms 12892 KB Output is correct
51 Correct 18 ms 12892 KB Output is correct
52 Correct 16 ms 12076 KB Output is correct
53 Correct 24 ms 12620 KB Output is correct
54 Correct 16 ms 12764 KB Output is correct
55 Correct 17 ms 13020 KB Output is correct
56 Correct 16 ms 12808 KB Output is correct