結果

問題 No.533 Mysterious Stairs
ユーザー deark1414deark1414
提出日時 2017-10-06 16:32:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 567 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 52,684 KB
実行使用メモリ 15,272 KB
最終ジャッジ日時 2023-08-10 16:58:15
合計ジャッジ時間 1,910 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,076 KB
testcase_01 AC 6 ms
15,176 KB
testcase_02 AC 7 ms
15,068 KB
testcase_03 AC 5 ms
15,068 KB
testcase_04 AC 6 ms
15,144 KB
testcase_05 AC 6 ms
15,128 KB
testcase_06 AC 6 ms
15,068 KB
testcase_07 AC 6 ms
15,124 KB
testcase_08 AC 5 ms
15,060 KB
testcase_09 AC 5 ms
15,068 KB
testcase_10 AC 6 ms
15,148 KB
testcase_11 AC 6 ms
15,124 KB
testcase_12 AC 6 ms
15,060 KB
testcase_13 AC 6 ms
15,076 KB
testcase_14 AC 6 ms
15,068 KB
testcase_15 AC 6 ms
15,068 KB
testcase_16 AC 6 ms
15,072 KB
testcase_17 AC 6 ms
15,272 KB
testcase_18 AC 6 ms
15,068 KB
testcase_19 AC 6 ms
15,204 KB
testcase_20 AC 9 ms
15,144 KB
testcase_21 AC 9 ms
15,068 KB
testcase_22 AC 16 ms
15,144 KB
testcase_23 AC 33 ms
15,128 KB
testcase_24 AC 33 ms
15,140 KB
testcase_25 AC 8 ms
15,124 KB
testcase_26 AC 30 ms
15,060 KB
testcase_27 AC 14 ms
15,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string.h>

using namespace std;
const int limn = 1e6;
int dp[limn+10][3];
int divn = 1e9 + 7;
int main(){
	memset(dp,0,sizeof(dp));
	int n;
	cin >> n;
	
	dp[0][0] = 1;
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 3;j++){
			for(int k = 0;k < 3;k++){
				if(i==0){
					dp[i+k+1][k] = (dp[i+k+1][k] + dp[i][j]) % divn;
				}else{
					if(j != k){
						dp[i+k+1][k] = (dp[i+k+1][k] + dp[i][j]) % divn;
					}
				}
			}
		}
	}
	
	int ans = 0;
	for(int i = 0;i < 3;i++) ans = (ans + dp[n][i]) % divn;
	
	cout << ans << endl;
	return 0;
}
0