結果

問題 No.533 Mysterious Stairs
ユーザー ひゅーらひゅーら
提出日時 2017-06-24 00:08:40
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,411 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 13,460 KB
最終ジャッジ日時 2024-04-15 01:12:12
合計ジャッジ時間 4,364 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
権限があれば一括ダウンロードができます

ソースコード

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