Submission #131912

#TimeUsernameProblemLanguageResultExecution timeMemory
131912dragonslayeritLinear Garden (IOI08_linear_garden)C++14
85 / 100
98 ms65540 KiB
#include <cstdio> #include <cassert> char str[1000005]; int MOD; struct State{ int max,curr; State(int max,int curr):max(max),curr(curr){ assert(curr>=0&&curr<=max); } int code(){ return max*3+curr; } 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]; int vis[1000005][9]; int complete(State prefix,int len){ if(prefix.max>2) return 0; if(len==0) return 1; if(vis[len][prefix.code()]) return memo[len][prefix.code()]; vis[len][prefix.code()]=true; return memo[len][prefix.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++){ 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:36: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:37: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...