Submission #00031


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
#define INF 1<<30
#define F first
#define S second
#define MOD 10000
ll n,k;
ll pasta[105];
ll memo[105][4][4];
ll dp(ll now,ll spa1,ll spa2){
if(memo[now][spa1][spa2]!=-1){
return memo[now][spa1][spa2];
}else if(now==n+1){
return 1;
}else if(pasta[now]!=0){
if(spa1==pasta[now]&&spa2==pasta[now]) return 0;
else return memo[now][spa1][spa2]=dp(now+1,pasta[now],spa1)%MOD;
}else{
ll sum=0;
for(ll i=1;i<=3;i++){
if(i!=spa1||i!=spa2){
sum+=dp(now+1,i,spa1)%MOD;
}
}
return memo[now][spa1][spa2]=sum%MOD;
}
}
int main(){
cin>>n>>k;
for(int i=0;i<105;i++){
for(int j=0;j<4;j++){
for(int k=0;k<4;k++){
memo[i][j][k]=-1;
}
}
}
for(int i=0;i<k;i++){
int a,b;
cin>>a>>b;
pasta[a]=b;
}
cout<<dp(1,0,0)<<endl;
return 0;
}

ステータス

項目 データ
問題 0003 - パスタ (Pasta)
ユーザー名 ei1728
投稿日時 2019-10-30 17:23:02
言語 C++14
状態 Accepted
得点 100
ソースコード長 986 Byte
最大実行時間 23 ms
最大メモリ使用量 604 KB

セット

セット 得点 Cases
1 入力1 20 / 20 *1.txt
2 入力2 20 / 20 *2.txt
3 入力3 20 / 20 *3.txt
4 入力4 20 / 20 *4.txt
5 入力5 20 / 20 *5.txt

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
2012-yo-t4-in1.txt AC 20 ms 476 KB
1
2012-yo-t4-in2.txt AC 20 ms 560 KB
2
2012-yo-t4-in3.txt AC 16 ms 520 KB
3
2012-yo-t4-in4.txt AC 21 ms 604 KB
4
2012-yo-t4-in5.txt AC 23 ms 564 KB
5