Submission #438876

#TimeUsernameProblemLanguageResultExecution timeMemory
438876SnowfallJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
35 ms3040 KiB
#include<bits/stdc++.h> using namespace std; char arr[200005]; int a[1000]; int qs[3][200005]; main() { int t,p; a['O']=1; a['I']=2; scanf("%d%d",&t,&p); scanf("%s",&arr[1]); for(int i = 1;i <= t;i++) { qs[a[arr[i]]][i]++; // printf("%d\n",arr[i]); for(int j = 0;j < 3;j++) qs[j][i]+=qs[j][i-1]; } int mn=1e9; for(int i = 1;i <= t;i++) { int ck=0; int pv=i; int sm=0; for(int j = 0;j < 3 && ck==j;j++) { int st=pv,ed=t; int tmn=1e9; while(st<=ed) { int md=(st+ed)/2; // printf("%d %d<--\n",qs[j][md],qs[j][pv-1]); if(qs[j][md]-qs[j][pv-1]>=p) { ed=md-1; tmn=min(tmn,md); } else { st=md+1; } } // printf("d %d %d %d\n",j,tmn,pv-1); if(tmn==1e9) break; if(qs[j][tmn]-qs[j][pv-1]==p) { sm+=tmn-pv+1-p; ck++; pv=tmn+1; } // printf("%d %d\n",pv,sm); } if(ck==3) mn=min(mn,sm); } if(mn!=1e9) printf("%d",mn); else printf("-1"); }

Compilation message (stderr)

ho_t2.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:15:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   15 |         qs[a[arr[i]]][i]++;
      |              ~~~~~^
ho_t2.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d%d",&t,&p);
      |     ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%s",&arr[1]);
      |     ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...