Submission #718062

#TimeUsernameProblemLanguageResultExecution timeMemory
718062niterJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
1 ms1864 KiB
#include <bits/stdc++.h> #define loop(i,a,b) for(int i=a;i<b;i++) #define pii pair<int,int> #define ff first #define ss second #define pb push_back #define ins insert #define mp make_pair using namespace std; void debug(){ cout << "\n"; } template<class T, class ...U> void debug(T a, U ...b){ cout << a << " "; debug(b...); } const int maxN = 200005; int main(){ int n, k; string s; cin >> n >> k >> s; deque<int> dqJ, dqO, dqI; int prevJ[maxN], sufI[maxN]; loop(i,0,n){ prevJ[i] = -1; sufI[i] = -1; } int ans = 2147483647; // J loop(i,0,n){ if(dqJ.size() < k){ if(s[i] == 'J'){ dqJ.pb(i); } } else{ prevJ[i] = dqJ.front(); if(s[i] == 'J'){ dqJ.pop_front(); dqJ.pb(i); } } } // I for(int i = n-1; i >= 0; i--){ if(dqI.size() < k){ if(s[i] == 'I'){ dqI.push_front(i); } } else{ sufI[i] = dqI.back(); if(s[i] == 'I'){ dqI.pop_back(); dqI.push_front(i); } } } // O loop(i,0,n){ if(dqO.size() < k){ if(s[i] == 'O'){ dqO.pb(i); } } else{ if(s[i] == 'O'){ dqO.pop_front(); dqO.pb(i); } if(prevJ[dqO.front()] != -1 && sufI[dqO.back()] != -1){ ans = min(ans, sufI[dqO.back()] - prevJ[dqO.front()] + 1 - k * 3); } } } cout << ans << "\n"; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:34:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         if(dqJ.size() < k){
      |            ~~~~~~~~~~~^~~
ho_t2.cpp:49:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         if(dqI.size() < k){
      |            ~~~~~~~~~~~^~~
ho_t2.cpp:64:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |         if(dqO.size() < k){
      |            ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...