Submission #212523

#TimeUsernameProblemLanguageResultExecution timeMemory
212523DystoriaXJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
18 ms2676 KiB
#include <bits/stdc++.h> using namespace std; int n, k; char s[200010]; vector<int> J, O, I; int lf[200010]; int ans = 1e9; int main(){ scanf("%d%d", &n, &k); scanf(" %s", s + 1); for(int i = 1; i <= n; i++){ if(s[i] == 'J') J.emplace_back(i); if(s[i] == 'O') O.emplace_back(i); if(s[i] == 'I') I.emplace_back(i); } for(int i = k - 1; i < (int) J.size(); i++){ lf[J[i]] = J[i - k + 1]; } for(int i = k - 1; i < (int) O.size(); i++){ auto it = upper_bound(J.begin(), J.end(), O[i - k + 1]); if(it == J.begin()) continue; --it; if(lf[*it] == 0) continue; lf[O[i]] = lf[*it]; } for(int i = k - 1; i < (int) I.size(); i++){ auto it = upper_bound(O.begin(), O.end(), I[i - k + 1]); if(it == O.begin()) continue; --it; if(lf[*it] == 0) continue; ans = min(ans, I[i] - lf[*it] + 1 - 3 * k); } if(ans == 1e9) ans = -1; printf("%d\n", ans); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %s", s + 1);
     ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...