Submission #364997

#TimeUsernameProblemLanguageResultExecution timeMemory
364997DymoJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
12 ms3312 KiB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
//#define endl "\n"
const ll maxn =1e4+10;
const ll mod=1e9+7;
const ll base=1e18;

vector<ll> vt;
vector<ll> vt1;
vector<ll> vt2;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
     ll n, k;
     cin>> n>> k;
    string s;
    cin>> s;
    ll cnt=0;
    for (auto to:s)
    {
        cnt++;
        if (to=='J')
        {
           vt.pb(cnt);
        }
        else if (to=='O')
        {
           vt1.pb(cnt);
        }
        else
        {
           vt2.pb(cnt);
        }
    }
    ll ans=base;
    for (int i=0;i+k-1<vt.size();i++)
    {
       ll st=vt[i];
       ll nxt=vt[i+k-1]+1;
    //   cout <<st<<" "<<nxt<<endl;
       auto h=lower_bound(vt1.begin(),vt1.end(),nxt)-vt1.begin();
    //   cout <<vt1[h]<<" "<<h<<endl;
       if (h+k-1>=vt1.size()) continue;
      // cout <<"WTF"<<endl;
       nxt=vt1[h+k-1]+1;
       h=lower_bound(vt2.begin(),vt2.end(),nxt)-vt2.begin();
       if (h+k-1>=vt2.size()) continue;
       ll ed=vt2[h+k-1];
        ans=min(ans,ed-st+1-3*k);
    }
    if (ans==base) ans=-1;
    cout <<ans<<endl;
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:49:23: 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]
   49 |     for (int i=0;i+k-1<vt.size();i++)
      |                  ~~~~~^~~~~~~~~~
ho_t2.cpp:56:17: 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]
   56 |        if (h+k-1>=vt1.size()) continue;
      |            ~~~~~^~~~~~~~~~~~
ho_t2.cpp:60:17: 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]
   60 |        if (h+k-1>=vt2.size()) continue;
      |            ~~~~~^~~~~~~~~~~~
ho_t2.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   25 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...