Submission #365331

#TimeUsernameProblemLanguageResultExecution timeMemory
365331AdOjis485JJOOII 2 (JOI20_ho_t2)C++14
100 / 100
13 ms3316 KiB
#include <iostream> #include <vector> #include <algorithm> #define int int64_t using namespace std; signed main() { int n, k; string s; cin >> n >> k >> s; vector<int> jvec; vector<int> ovec; vector<int> ivec; for(int i = 0; i < n; i ++) { if(s[i] == 'J') jvec.push_back(i); else if(s[i] == 'O') ovec.push_back(i); else ivec.push_back(i); } int ans = 1e9; int j = 0; int j2 = 0; for(int i = 0; i + k <= jvec.size(); i ++) { while(j < ovec.size() && ovec[j] < jvec[i + k - 1]) j ++; if(j + k > ovec.size()) continue; while(j2 < ivec.size() && ivec[j2] < ovec[j + k - 1]) j2 ++; if(j2 + k <= ivec.size()) { // cerr << i << " " << j << " " << j2 << " " << j2 + k - 4 - i << '\n'; ans = min(ivec[j2 + k - 1] - jvec[i] - 3 * k + 1, ans); } } if(ans == 1e9) cout << "-1\n"; else cout << ans << '\n'; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:28:26: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i + k <= jvec.size(); i ++)
      |                    ~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:30:17: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         while(j < ovec.size() && ovec[j] < jvec[i + k - 1]) j ++;
      |               ~~^~~~~~~~~~~~~
ho_t2.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         if(j + k > ovec.size()) continue;
      |            ~~~~~~^~~~~~~~~~~~~
ho_t2.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         while(j2 < ivec.size() && ivec[j2] < ovec[j + k - 1]) j2 ++;
      |               ~~~^~~~~~~~~~~~~
ho_t2.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if(j2 + k <= ivec.size())
      |            ~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...