結果

問題 No.533 Mysterious Stairs
ユーザー ひゅーら
提出日時 2017-06-24 00:08:40
言語 C
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 1,411 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 29,696 KB
実行使用メモリ 13,364 KB
最終ジャッジ日時 2024-10-04 08:13:18
合計ジャッジ時間 4,388 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#define MAX 1000000007

#include <stdio.h>
#include <stdlib.h>

typedef struct Node{
	int step;
	struct Node* child[3];//n進む時その子は[n-1]
} Node;

int count(int n, int next, Node* root, int table[][3]){
	//rootからnext進んだ時、あとに残された可能性の数
	Node* node;
	root->child[next-1] = node;
	node->step = root->step + next;
	if(node->step == n){//next進むとぴったりの時
		return 1;
	}
	else if(node->step > n){//行き過ぎのとき
		return 0;
	}
	else{//まだのとき
		int a = 0;
		int next1, next2;
		if(next == 1){
			next1 = 2;
			next2 = 3;
		}
		else if(next == 2){
			next1 = 1;
			next2 = 3;
		}
		else{
			next1 = 1;
			next2 = 2;
		}
		if(table[node->step][next1] >= 0){//表の有無
			a += table[node->step][next1];
		}
		else{
			a += count(n, next1, node, table);
		}
		if(table[node->step][next2] >= 0){
			a += table[node->step][next2];
		}
		else{
			a += count(n, next2, node, table);
		}
		table[root->step][next] = a;
		return a % MAX;
	}
}

#include <stdio.h>
int main(void){
	int n;
	scanf("%d", &n);
	int table[n][3];
	//現在j段目、次進むstep数はkのとき、table[j][k]
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 3; j++){
			table[i][j] = -1;
		}
	}
	Node* root;
	root->step = 0;
	int ans = 0;
	ans += count(n, 1, root, table);
	ans += count(n, 2, root, table);
	ans += count(n, 3, root, table);
	ans %= MAX;
	return 0;
}
0