Submission #335627

#TimeUsernameProblemLanguageResultExecution timeMemory
335627JoshcJJOOII 2 (JOI20_ho_t2)C++11
100 / 100
23 ms1772 KiB
#include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { int n, k, ans=1e9; scanf("%d%d", &n, &k); char c; vector<int> j, o, i; for (int l=0; l<n; l++) { scanf(" %c", &c); if (c == 'J') j.push_back(l); else if (c == 'O') o.push_back(l); else i.push_back(l); } for (int s=0; s<j.size()-k+1; s++) { int cur = j[s+k-1]; if (cur > o.back()) break; cur = lower_bound(o.begin(), o.end(), cur)-o.begin(); if (cur+k > o.size()) break; cur = o[cur+k-1]; if (cur > i.back()) break; cur = lower_bound(i.begin(), i.end(), cur)-i.begin(); if (cur+k <= i.size()) ans = min(ans, i[cur+k-1]-j[s]+1); } printf("%d\n", ans==1e9 ? -1 : ans-3*k); }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int s=0; s<j.size()-k+1; s++) {
      |                   ~^~~~~~~~~~~~~
ho_t2.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         if (cur+k > o.size()) break;
      |             ~~~~~~^~~~~~~~~~
ho_t2.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         if (cur+k <= i.size()) ans = min(ans, i[cur+k-1]-j[s]+1);
      |             ~~~~~~^~~~~~~~~~~
ho_t2.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |         scanf(" %c", &c);
      |         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...