Submission #594028

#TimeUsernameProblemLanguageResultExecution timeMemory
594028stevancvJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
5 ms2536 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 2e5 + 2; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; string s; cin >> s; vector<int> a, b; vector<int> pref(n); for (int i = 0; i < n; i++) { if (i > 0) pref[i] += pref[i - 1]; if (s[i] == 'J') a.push_back(i); if (s[i] == 'O') pref[i]++; if (s[i] == 'I') b.push_back(i); } auto Get = [&] (int l, int r) { if (l > r) return 0; int o = pref[r]; if (l > 0) o -= pref[l - 1]; }; int ans = 1e9; int j = 0; for (int i = k - 1; i < a.size(); i++) { while (j < b.size() && pref[b[j]] - pref[a[i]] < k) j++; if (j == b.size()) continue; if (pref[b[j]] - pref[a[i]] >= k && b.size() - j >= k) smin(ans, b[j + k - 1] - a[i - k + 1] + 1 - 3 * k); } if (ans == 1e9) ans = -1; cout << ans << en; return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = k - 1; i < a.size(); i++) {
      |                         ~~^~~~~~~~~~
ho_t2.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         while (j < b.size() && pref[b[j]] - pref[a[i]] < k) j++;
      |                ~~^~~~~~~~~~
ho_t2.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if (j == b.size()) continue;
      |             ~~^~~~~~~~~~~
ho_t2.cpp:36:58: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |         if (pref[b[j]] - pref[a[i]] >= k && b.size() - j >= k) smin(ans, b[j + k - 1] - a[i - k + 1] + 1 - 3 * k);
      |                                             ~~~~~~~~~~~~~^~~~
ho_t2.cpp:26:10: warning: variable 'Get' set but not used [-Wunused-but-set-variable]
   26 |     auto Get = [&] (int l, int r) {
      |          ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...