Submission #997767

#TimeUsernameProblemLanguageResultExecution timeMemory
997767mnieplowiczJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
13 ms2144 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<char> s(n); vector<int> J, O, I; for(int i = 0; i < n; i++){ cin >> s[i]; if(s[i] == 'J') J.push_back(i); if(s[i] == 'O') O.push_back(i); if(s[i] == 'I') I.push_back(i); } int res = 1e9; for(int i = 0; i < J.size() - k + 1; i++){ int a = J[i + k - 1]; int b = lower_bound(O.begin(), O.end(), a) - O.begin(); if(b + k - 1 >= O.size()) continue; int c = lower_bound(I.begin(), I.end(), O[b + k - 1]) - I.begin(); if(c + k - 1 >= I.size()) continue; res = min(res, I[c + k - 1] - J[i] - k * 3 + 1); } if(res == 1e9) cout << -1 << '\n'; else cout << res << '\n'; return 0; }

Compilation message (stderr)

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