Submission #365606

#TimeUsernameProblemLanguageResultExecution timeMemory
365606RainbowbunnyJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
15 ms1892 KiB
#include <iostream> #include <vector> int n, k; std::vector <int> J, O, I; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); std::cin >> n >> k; for(int i = 1; i <= n; i++) { char x; std::cin >> x; if(x == 'J') { J.push_back(i); } else if(x == 'O') { O.push_back(i); } else { I.push_back(i); } } int ans = 1e9; for(int i = 0; i + k <= J.size(); i++) { int l = J[i]; int r = J[i + k - 1]; r = std::lower_bound(O.begin(), O.end(), r) - O.begin(); r = r + k - 1; if(r >= O.size()) { continue; } r = O[r]; r = std::lower_bound(I.begin(), I.end(), r) - I.begin(); r = r + k - 1; if(r >= I.size()) { continue; } r = I[r]; ans = std::min(ans, r - l + 1); } if(ans > n) { std::cout << -1; return 0; } std::cout << ans - 3 * k; }

Compilation message (stderr)

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