結果

問題 No.533 Mysterious Stairs
ユーザー hogekihogeki
提出日時 2017-07-22 23:19:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 1,289 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 110,436 KB
実行使用メモリ 54,220 KB
最終ジャッジ日時 2024-04-17 15:59:49
合計ジャッジ時間 2,253 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
24,108 KB
testcase_01 AC 23 ms
23,660 KB
testcase_02 AC 18 ms
23,620 KB
testcase_03 AC 20 ms
23,788 KB
testcase_04 AC 18 ms
23,988 KB
testcase_05 AC 18 ms
23,892 KB
testcase_06 AC 19 ms
23,728 KB
testcase_07 AC 19 ms
21,688 KB
testcase_08 AC 19 ms
23,888 KB
testcase_09 AC 19 ms
23,760 KB
testcase_10 AC 19 ms
23,644 KB
testcase_11 AC 18 ms
23,788 KB
testcase_12 AC 19 ms
25,588 KB
testcase_13 AC 19 ms
23,780 KB
testcase_14 AC 20 ms
25,728 KB
testcase_15 AC 20 ms
25,952 KB
testcase_16 AC 19 ms
24,008 KB
testcase_17 AC 20 ms
25,716 KB
testcase_18 AC 20 ms
25,880 KB
testcase_19 AC 19 ms
21,812 KB
testcase_20 AC 25 ms
26,432 KB
testcase_21 AC 26 ms
26,808 KB
testcase_22 AC 41 ms
35,020 KB
testcase_23 AC 72 ms
53,692 KB
testcase_24 AC 73 ms
54,220 KB
testcase_25 AC 27 ms
26,544 KB
testcase_26 AC 69 ms
49,836 KB
testcase_27 AC 35 ms
30,772 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problem533
{
    class Program
    {
        const long M = 1000000007;

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            if(N == 1 || N == 2)
            {
                Console.WriteLine(1);
                return;
            }
            else if(N == 3)
            {
                Console.WriteLine(3);
                return;
            }
            
            long[,] dp = new long[N + 1, 4];

            dp[1, 1] = 1;
            dp[2, 2] = 1;
            dp[3, 3] = 1;
            dp[3, 2] = 1;
            dp[3, 1] = 1;

            for(int i = 4; i <= N; i++)
            {
                dp[i, 1] = (dp[i - 1, 2] + dp[i - 1, 3]) % M;
                //Console.WriteLine("dp[{0},1] = {1}", i, dp[i, 1]);
                dp[i, 2] = (dp[i - 2, 1] + dp[i - 2, 3]) % M;
                //Console.WriteLine("dp[{0},2] = {1}", i, dp[i, 2]);

                dp[i, 3] = (dp[i - 3, 1] + dp[i - 3, 2]) % M;
                //Console.WriteLine("dp[{0},3] = {1}", i, dp[i, 3]);

            }

            Console.WriteLine(((dp[N,1] + dp[N, 2]) % M + dp[N,3]) % M);

        }
    }
}
0