結果

問題 No.533 Mysterious Stairs
ユーザー くれちーくれちー
提出日時 2017-06-23 22:56:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 2,226 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 116,616 KB
実行使用メモリ 41,856 KB
最終ジャッジ日時 2024-04-15 00:58:42
合計ジャッジ時間 2,617 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
19,072 KB
testcase_01 AC 24 ms
19,200 KB
testcase_02 AC 24 ms
19,072 KB
testcase_03 AC 23 ms
18,944 KB
testcase_04 AC 25 ms
19,072 KB
testcase_05 AC 27 ms
19,328 KB
testcase_06 AC 25 ms
18,944 KB
testcase_07 AC 26 ms
19,200 KB
testcase_08 AC 27 ms
19,200 KB
testcase_09 AC 24 ms
19,072 KB
testcase_10 AC 25 ms
19,072 KB
testcase_11 AC 24 ms
19,200 KB
testcase_12 AC 24 ms
19,072 KB
testcase_13 AC 23 ms
19,200 KB
testcase_14 AC 23 ms
19,072 KB
testcase_15 AC 24 ms
19,200 KB
testcase_16 AC 25 ms
18,944 KB
testcase_17 AC 27 ms
19,072 KB
testcase_18 AC 25 ms
19,148 KB
testcase_19 AC 25 ms
19,152 KB
testcase_20 AC 32 ms
20,864 KB
testcase_21 AC 31 ms
20,992 KB
testcase_22 AC 50 ms
27,392 KB
testcase_23 AC 88 ms
41,344 KB
testcase_24 AC 88 ms
41,856 KB
testcase_25 AC 31 ms
20,992 KB
testcase_26 AC 82 ms
38,400 KB
testcase_27 AC 44 ms
24,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

#pragma warning disable IDE0011
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

class ReaderWriter
{
    protected int _Index;
    protected string[] _Line;

    public void R(char sep = ' ') { _Line = Console.ReadLine().Split(sep); _Index = 0; }
    public string S() => _Line[_Index++];
    public string[] Ss() => _Line.Skip(_Index++).ToArray();
    public char C() => char.Parse(_Line[_Index++]);
    public char[] Cs() => _Line.Skip(_Index++).Select(char.Parse).ToArray();
    public int I() => int.Parse(_Line[_Index++]);
    public int[] Is() => _Line.Skip(_Index++).Select(int.Parse).ToArray();
    public long L() => long.Parse(_Line[_Index++]);
    public long[] Ls() => _Line.Skip(_Index++).Select(long.Parse).ToArray();
    public double F() => double.Parse(_Line[_Index++]);
    public double[] Fs() => _Line.Skip(_Index++).Select(double.Parse).ToArray();
    public decimal D() => decimal.Parse(_Line[_Index++]);
    public decimal[] Ds() => _Line.Skip(_Index++).Select(decimal.Parse).ToArray();
    public BigInteger B() => BigInteger.Parse(_Line[_Index++]);
    public BigInteger[] Bs() => _Line.Skip(_Index++).Select(BigInteger.Parse).ToArray();

    public void Write(params object[] xs)
    {
        Console.Write(xs.First());
        foreach (var x in xs.Skip(1)) Console.Write(" " + x);
        Console.WriteLine();
    }
}

class Program
{
    static void Main()
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        Solve(new ReaderWriter());
        Console.Out.Flush();
    }

    static void Solve(ReaderWriter rw)
    {
        rw.R(); var n = rw.L();

        const long mod = 1000000007;

        var dp = new long[1000001, 3];
        dp[1, 0] = 1; dp[1, 1] = 0; dp[1, 2] = 0;
        dp[2, 0] = 0; dp[2, 1] = 1; dp[2, 2] = 0;
        dp[3, 0] = 1; dp[3, 1] = 1; dp[3, 2] = 1;

        for (var i = 4; i <= n; i++)
        {
            dp[i, 0] = (dp[i - 1, 1] + dp[i - 1, 2]) % mod;
            dp[i, 1] = (dp[i - 2, 0] + dp[i - 2, 2]) % mod;
            dp[i, 2] = (dp[i - 3, 0] + dp[i - 3, 1]) % mod;
        }

        rw.Write((dp[n, 0] + dp[n, 1] + dp[n, 2]) % mod);
    }
}
0