Submission #716202

#TimeUsernameProblemLanguageResultExecution timeMemory
716202YeoBLJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
11 ms3032 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define mp make_pair #define pb emplace_back int cn(char ch){ if (ch == 'J') return 0; else if (ch == 'O') return 1; else return 2; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, ans = 1e9, st, cur; cin >> n >> k; string s; cin >> s; vector <int> pos[3]; for (int i = 0; i < s.size(); i++){ pos[cn(s[i])].pb(i); } for (int i = 0; i + k - 1 < pos[0].size(); i++){ cur = pos[0][i + k - 1]; int tmp = (upper_bound(pos[1].begin(), pos[1].end(), cur) - pos[1].begin()) + k - 1; if (tmp >= pos[1].size()) continue; else cur = pos[1][tmp]; tmp = (upper_bound(pos[2].begin(), pos[2].end(), cur) - pos[2].begin()) + k - 1; if (tmp >= pos[2].size()) continue; cur = pos[2][tmp]; //cerr << pos[0][i] << ' ' << cur << '\n'; ans = min(ans, cur - pos[0][i] + 1 - 3 * k); } if (ans > n) cout << -1; else cout << ans; }

Compilation message (stderr)

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:19:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for (int i = 0; i < s.size(); i++){
      |                  ~~^~~~~~~~~~
ho_t2.cpp:22:28: 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]
   22 |  for (int i = 0; i + k - 1 < pos[0].size(); i++){
      |                  ~~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:25:11: 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]
   25 |   if (tmp >= pos[1].size()) continue;
      |       ~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:28:11: 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 (tmp >= pos[2].size()) continue;
      |       ~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:16:23: warning: unused variable 'st' [-Wunused-variable]
   16 |  int n, k, ans = 1e9, st, cur; cin >> n >> k;
      |                       ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...