Submission #131916

#TimeUsernameProblemLanguageResultExecution timeMemory
131916dragonslayeritLinear Garden (IOI08_linear_garden)C++14
100 / 100
180 ms46396 KiB
#include <cstdio> #include <cassert> char str[1000005]; int MOD; struct State{ char max,curr; State(char max,char curr):max(max),curr(curr){ assert(curr>=0&&curr<=max); } State up()const{ return (curr==max)?State(max+1,max+1):State(max,curr+1); } State down()const{ return (curr==0)?State(max+1,0):State(max,curr-1); } }; int memo[1000005][9]; bool vis[1000005][9]; int complete(State prefix,int len){ if(prefix.max>2) return 0; if(len==0) return 1; int code=prefix.max*3+prefix.curr; if(vis[len][code]) return memo[len][code]; vis[len][code]=true; return memo[len][code]=(complete(prefix.up(),len-1)+complete(prefix.down(),len-1))%MOD; } int main(){ int N; scanf("%d %d",&N,&MOD); scanf("%s",str); int ans=1; State prefix(0,0); for(int i=0;i<N;i++){ for(int s=0;s<3;s++){ for(int t=0;t<=s;t++){ complete(State(s,t),i); } } } for(int i=0;i<N;i++){ if(str[i]=='P'){ ans=(ans+complete(prefix.down(),N-i-1))%MOD; prefix=prefix.up(); }else{ prefix=prefix.down(); } } printf("%d\n",ans); return 0; }

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&N,&MOD);
   ~~~~~^~~~~~~~~~~~~~~~~
linear_garden.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",str);
   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...