Submission #365330

#TimeUsernameProblemLanguageResultExecution timeMemory
365330AdOjis485JJOOII 2 (JOI20_ho_t2)C++17
13 / 100
2057 ms3048 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;

    for(int i = 0; i + k <= jvec.size(); i ++)
    {
        int j = 0;
        while(j < ovec.size() && ovec[j] < jvec[i + k - 1]) j ++;
        if(j + k > ovec.size()) continue;
        int j2 = 0;
        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:26: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]
   26 |     for(int i = 0; i + k <= jvec.size(); i ++)
      |                    ~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:29: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]
   29 |         while(j < ovec.size() && ovec[j] < jvec[i + k - 1]) j ++;
      |               ~~^~~~~~~~~~~~~
ho_t2.cpp:30: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]
   30 |         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...