이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
int N,M;
#define MAX 1100000
bool existe[MAX][33][5][2];
int tab[MAX][33][5][2];
int base=2;
std::string s;
int dp(int pos,int pente,int soma,bool desceu){
int atual = soma;
for(int i=0;i!=5;++i){
if(pente&(1<<i)){
int k = i-2;
int x = atual-k;
if(x<-2||x>2){return 0;}
}
}
if(pos==N){
return 1;
}
if(existe[pos][pente][soma+2][desceu])return tab[pos][pente][soma+2][desceu];
existe[pos][pente][soma+2][desceu]=true;
if(desceu){
int alpha=0,beta=0;
if(atual<2){
alpha=dp(pos+1,pente|(1<<(soma+3)),soma+1,1);
}
if(atual>-2){
beta=dp(pos+1,pente|(1<<(soma+1)),soma-1,1);
}
return tab[pos][pente][soma+2][desceu] = ( alpha + beta ) % M;
}else {
if(s[pos]=='L'){
if(atual>-2){///Aperta L
return tab[pos][pente][soma+2][desceu] = dp(pos+1,pente|(1<<(soma+1)),soma-1,0);
}
else return 0;
}else {
int alpha=0,beta=0;
if(atual<2){///Aperta P
assert(atual+3<5);
alpha=dp(pos+1,pente|(1<<(soma+3)),soma+1,0);
}
if(atual>-2){///Aperta L
beta=dp(pos+1,pente|(1<<(soma+1)),soma-1,1);
}
return tab[pos][pente][soma+2][desceu] = ( alpha + beta ) % M;
}
}
}
int main()
{
std::cin>>N>>M>>s;
std::cout<<dp(0,(1<<2),0,0)<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |