Submission #895517

#TimeUsernameProblemLanguageResultExecution timeMemory
895517adkjtJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
296 ms2660 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define ll long long #define pii pair<int,int> string s; int OO[222222]; vector<int> II,JJ; int main(){ int n,k; //printf("??"); scanf("%d %d",&n,&k); cin>>s; //printf("SS"); for(int i=0;i<n;i++) { OO[i]=OO[i-1]; if(s[i]=='J') JJ.push_back(i); else if(s[i]=='I') II.push_back(i); else{ OO[i]=OO[i-1]+1; if(!i) OO[i]=1; } if(!i) OO[i]=0; } int ans=1e9; //printf("%d\n",II.size()); //printf("YY"); for(int itJ=0;itJ<JJ.size()-k+1;itJ++) { //printf("%d\n",JJ[itJ+k-1]); int itI=lower_bound(II.begin(),II.end(),JJ[itJ+k-1])-II.begin(); // printf("%d\n",itI); if(itI+k-1>=II.size()) continue; while(OO[II[itI]]-OO[JJ[itJ+k-1]]<k) { //printf("YOYO\n"); itI++; if(itI+k-1>=II.size()) break; } if(itI+k-1>=II.size()) continue; //printf("%d %d %d %d\n",II[itI+k-1],itI+k-1,JJ[itJ],itJ); ans=min(ans,II[itI+k-1]-JJ[itJ]+1-(3*k)); //printf("%d ",ans); } if(ans>333333) printf("-1"); else printf("%d",ans); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int itJ=0;itJ<JJ.size()-k+1;itJ++)
      |                   ~~~^~~~~~~~~~~~~~
ho_t2.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if(itI+k-1>=II.size()) continue;
      |            ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |                 if(itI+k-1>=II.size())
      |                    ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         if(itI+k-1>=II.size()) continue;
      |            ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...