Submission #1115711

#TimeUsernameProblemLanguageResultExecution timeMemory
1115711staszic_ojuzJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
22 ms13020 KiB
#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[pref[aktj][1]+k-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 (stderr)

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:62:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |                 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...