Submission #774445

#TimeUsernameProblemLanguageResultExecution timeMemory
774445stefanneaguJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
1 ms212 KiB
#include <iostream> #include <vector> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; vector<int> J, O, I; for(int i = 0; i < n; 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 ans = 1e9; for(int i = 0; i < J.size() - k + 1; i ++) { int pos_o = lower_bound(O.begin(), O.end(), J[i + k - 1]) - O.begin(); if(pos_o <= O.size() - k + 1) { int pos_i = lower_bound(I.begin(), I.end(), O[pos_o + k - 1]) - I.begin(); if(pos_i <= I.size() - k + 1) { int term = I[pos_i + k - 1]; ans = min(ans, term - J[i] + 1 - 3 * k); } } } cout << ans; return 0; }

Compilation message (stderr)

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