Submission #994370

#TimeUsernameProblemLanguageResultExecution timeMemory
994370rsinventorJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
11 ms3300 KiB
// // main.cpp // jjooii_2 // // Created by Raunak Singh on 6/7/24. // #include "bits/stdc++.h" using namespace std; #define ll long long int main() { ll n, k; cin >> n >> k; string s; cin >> s; vector<ll> jidxs; vector<ll> oidxs; vector<ll> iidxs; for(ll i = 0; i < n; i++) { if(s[i]=='J') { jidxs.push_back(i); } else if(s[i]=='O') { oidxs.push_back(i); } else if(s[i]=='I') { iidxs.push_back(i); } } if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) { cout << -1 << endl; return 0; } ll ans = -1; for(ll i = 0; i < jidxs.size()-k+1; i++) { // ll pos = 0; // for(ll j = i; j < i+k-1; j++) { // pos += jidxs[j+1] - jidxs[j] - 1; // } ll o_idx = lower_bound(oidxs.begin(), oidxs.end(), jidxs[i+k-1]) - oidxs.begin(); if(o_idx+k-1>=oidxs.size()) { continue; } // for(ll j = o_idx; j < o_idx+k-1; j++) { // pos += oidxs[j+1] - oidxs[j] - 1; // } ll i_idx = lower_bound(iidxs.begin(), iidxs.end(), oidxs[o_idx+k-1]) - iidxs.begin(); if(i_idx+k-1>=iidxs.size()) { continue; } // for(ll j = i_idx; j < i_idx + k -1; j++) { // pos += iidxs[j+1] - iidxs[j] - 1; // } ll pos = iidxs[i_idx+k-1] - jidxs[i] - 3*k + 1; if(ans==-1 || pos < ans) { ans = pos; } } cout << ans << endl; return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:29:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   29 |     if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) {
      |        ~~~~~~~~~~~~^~
ho_t2.cpp:29:38: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   29 |     if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) {
      |                          ~~~~~~~~~~~~^~
ho_t2.cpp:29:56: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   29 |     if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) {
      |                                            ~~~~~~~~~~~~^~
ho_t2.cpp:34:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   34 |     for(ll i = 0; i < jidxs.size()-k+1; i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:40:21: 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]
   40 |         if(o_idx+k-1>=oidxs.size()) {
      |            ~~~~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:47:21: 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]
   47 |         if(i_idx+k-1>=iidxs.size()) {
      |            ~~~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...