Submission #227130

#TimeUsernameProblemLanguageResultExecution timeMemory
227130maruiiJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
10 ms2044 KiB
#include <bits/stdc++.h> using namespace std; #define eack emplace_back int N, K; char S[200005]; vector<int> J, O, I; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> N >> K >> S + 1; for (int i = 1; i <= N; ++i) { if (S[i] == 'J') J.eack(i); if (S[i] == 'O') O.eack(i); if (S[i] == 'I') I.eack(i); } int ans = N; for (int i = 0, j = 0, k = 0; i + K - 1 < O.size(); ++i) { while (j + K < J.size() && J[j + K] < O[i]) ++j; while (k + K < I.size() && I[k] < O[i + K - 1]) ++k; if (J[j + K - 1] < O[i] && O[i + K - 1] < I[k]) ans = min(ans, I[k + K - 1] - J[j] + 1 - 3 * K); } if (ans == N) ans = -1; cout << ans; return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:10:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  cin >> N >> K >> S + 1;
                   ~~^~~
ho_t2.cpp:17:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0, j = 0, k = 0; i + K - 1 < O.size(); ++i) {
                                ~~~~~~~~~~^~~~~~~~~~
ho_t2.cpp:18:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (j + K < J.size() && J[j + K] < O[i]) ++j;
          ~~~~~~^~~~~~~~~~
ho_t2.cpp:19:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (k + K < I.size() && I[k] < O[i + K - 1]) ++k;
          ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...