Submission #994342

#TimeUsernameProblemLanguageResultExecution timeMemory
994342rsinventorJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
1 ms348 KiB
// // main.cpp // jjooii_2 // // Created by Raunak Singh on 6/7/24. // #include "bits/stdc++.h" using namespace std; int main(int argc, const char * argv[]) { // insert code here... int n, k; cin >> n >> k; string s; cin >> s; vector<int> jidxs; vector<int> oidxs; vector<int> iidxs; for(int 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; } int ans = -1; for(int i = 0; i < jidxs.size()-k+1; i++) { int pos = 0; for(int j = i; j < i+k-1; j++) { pos += jidxs[j+1] - jidxs[j] - 1; } int o_idx = lower_bound(oidxs.begin(), oidxs.end(), jidxs[i+k-1]) - oidxs.begin(); if(o_idx>=oidxs.size()) { continue; } for(int j = o_idx; j < o_idx+k-1; j++) { pos += oidxs[j+1] - oidxs[j] - 1; } int i_idx = lower_bound(iidxs.begin(), iidxs.end(), oidxs[o_idx+k-1]) - iidxs.begin(); if(i_idx>=iidxs.size()) { continue; } for(int j = i_idx; j < i_idx + k -1; j++) { pos += iidxs[j+1] - iidxs[j] - 1; } if(ans==-1 || pos < ans) { ans = pos; } } cout << ans << endl; return 0; }

Compilation message (stderr)

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