Submission #209247

#TimeUsernameProblemLanguageResultExecution timeMemory
209247my99nJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
25 ms1792 KiB
#include<bits/stdc++.h> using namespace std; string s; vector<int> J, O, I; int main(){ int n, k; scanf("%d %d", &n, &k); cin >> s; for (int i = 0; i < s.size(); 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 = k-1; i < J.size(); i++) { int firstj = J[i-k+1], lastj = J[i]; int lasto = upper_bound(O.begin(), O.end(), lastj)-O.begin() + k-1; if (lasto >= O.size()) break; lasto = O[lasto]; int lasti = upper_bound(I.begin(), I.end(), lasto)-I.begin() + k-1; if (lasti >= I.size()) break; lasti = I[lasti]; ans = min(ans, lasti-firstj-3*k+1); } printf("%d", ans==1e9?-1:ans); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:8:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++) {
                     ~~^~~~~~~~~~
ho_t2.cpp:14:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = k-1; i < J.size(); i++)  {
                       ~~^~~~~~~~~~
ho_t2.cpp:17:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (lasto >= O.size()) break;
             ~~~~~~^~~~~~~~~~~
ho_t2.cpp:20:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (lasti >= I.size()) break;
             ~~~~~~^~~~~~~~~~~
ho_t2.cpp:7:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n, k; scanf("%d %d", &n, &k); cin >> s;
               ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...