Submission #484698

#TimeUsernameProblemLanguageResultExecution timeMemory
484698Jarif_RahmanJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
12 ms2016 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const int inf = 1e9; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, k; str s; cin >> n >> k >> s; vector<int> J, O, I; for(int i = 0; i < n; i++){ if(s[i] == 'J') J.pb(i); if(s[i] == 'O') O.pb(i); if(s[i] == 'I') I.pb(i); } int ans = inf; for(int i = k-1; i < O.size(); i++){ int cur = n; cur-=3*k; auto it = lower_bound(J.begin(), J.end(), O[i-k+1]); int j = it-J.begin(); j--; j-=k-1; if(j < 0) continue; cur-=J[j]; it = lower_bound(I.begin(), I.end(), O[i]); if(it == I.end()) continue; j = it-I.begin(); j+=k-1; if(j >= I.size()) continue; cur-=n-I[j]-1; ans = min(ans, cur); } if(ans == inf) ans = -1; cout << ans << "\n"; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = k-1; i < O.size(); i++){
      |                      ~~^~~~~~~~~~
ho_t2.cpp:38:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if(j >= I.size()) continue;
      |            ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...