Submission #956343

#TimeUsernameProblemLanguageResultExecution timeMemory
956343Dennis_JasonJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
6 ms23900 KiB
#include <bits/stdc++.h> #define NMAX 500001 #define pb push_back #define MOD 1000000007 #define nl '\n' #define INF 0x3f3f3f3f #define pii pair<int,int> using namespace std; ifstream fin("aib.in"); ofstream fout("aib.out"); int n,k,ans=INF; string s; set<int>v[NMAX]; char J='J'; char O='O'; char I='I'; signed main() { cin>>n>>k; cin>>s; s="#"+s; for(int i=1;i<=n;++i) { v[s[i]-'0'].insert(i); // cout<<s[i]; } if(v[J-'0'].size()<k||v[O-'0'].size()<k||v[I-'0'].size()<k) { cout<<-1; return 0; } for(int i=1;i<=v[J-'0'].size()-k+1;++i) { auto it_J=v[J-'0'].begin(); advance(it_J,i+k-1); if(*it_J>=n-1) continue; auto it_O= upper_bound(v[O-'0'].begin(),v[O-'0'].end(),*it_J); advance(it_O,k-1); if(*it_O>=n-1) continue; auto it_I= upper_bound(v[I-'0'].begin(),v[I-'0'].end(),*it_O); advance(it_I,k-1); //cout<<(*it_J-k)<<" "<<(*it_I)<<nl; ans=min(ans,((*it_I-(*it_J-k)+1)-(3*k))); } if(ans<0) cout<<-1; else cout<<ans; return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:29:23: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if(v[J-'0'].size()<k||v[O-'0'].size()<k||v[I-'0'].size()<k)
      |        ~~~~~~~~~~~~~~~^~
ho_t2.cpp:29:42: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if(v[J-'0'].size()<k||v[O-'0'].size()<k||v[I-'0'].size()<k)
      |                           ~~~~~~~~~~~~~~~^~
ho_t2.cpp:29:61: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if(v[J-'0'].size()<k||v[O-'0'].size()<k||v[I-'0'].size()<k)
      |                                              ~~~~~~~~~~~~~~~^~
ho_t2.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=1;i<=v[J-'0'].size()-k+1;++i)
      |                 ~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...