Submission #987283

#TimeUsernameProblemLanguageResultExecution timeMemory
987283aykhnJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
10 ms3296 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 0x3F3F3F3F signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, K; cin >> n >> K; string s; cin >> s; vector<int> v[3]; for (int i = 0; i < n; i++) v[(s[i] == 'O') + (s[i] == 'I') * 2].push_back(i); int ans = inf; for (int i = 0; i + K <= v[0].size(); i++) { auto it = lower_bound(v[1].begin(), v[1].end(), v[0][i + K - 1]); if (it == v[1].end()) break; int j = it - v[1].begin(); if (j + K > v[1].size()) break; it = lower_bound(v[2].begin(), v[2].end(), v[1][j + K - 1]); if (it == v[2].end()) break; int k = it - v[2].begin(); if (k + K > v[2].size()) break; ans = min(ans, (v[2][k + K - 1] - v[0][i] + 1) - 3 * K); } cout << (ans >= inf ? -1 : ans) << '\n'; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i + K <= v[0].size(); i++)
      |                     ~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:24:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         if (j + K > v[1].size()) break;
      |             ~~~~~~^~~~~~~~~~~~~
ho_t2.cpp:28:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         if (k + K > v[2].size()) break;
      |             ~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...