結果

問題 No.314 ケンケンパ
ユーザー AreTrashAreTrash
提出日時 2018-05-25 11:23:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 98 ms / 1,000 ms
コード長 2,470 bytes
コンパイル時間 2,500 ms
コンパイル使用メモリ 109,684 KB
実行使用メモリ 43,536 KB
最終ジャッジ日時 2023-09-11 03:22:42
合計ジャッジ時間 4,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
43,284 KB
testcase_01 AC 56 ms
20,660 KB
testcase_02 AC 55 ms
20,736 KB
testcase_03 AC 56 ms
20,736 KB
testcase_04 AC 57 ms
22,828 KB
testcase_05 AC 57 ms
20,724 KB
testcase_06 AC 56 ms
22,676 KB
testcase_07 AC 57 ms
20,792 KB
testcase_08 AC 57 ms
22,780 KB
testcase_09 AC 58 ms
22,784 KB
testcase_10 AC 56 ms
18,792 KB
testcase_11 AC 56 ms
22,780 KB
testcase_12 AC 56 ms
20,676 KB
testcase_13 AC 56 ms
20,736 KB
testcase_14 AC 57 ms
22,780 KB
testcase_15 AC 57 ms
20,692 KB
testcase_16 AC 58 ms
18,584 KB
testcase_17 AC 62 ms
22,512 KB
testcase_18 AC 78 ms
29,260 KB
testcase_19 AC 98 ms
43,536 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace No314
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var dp = new ModInt[N + 1, 3];
            dp[1, 0] = 1;

            for (var i = 2; i <= N; i++)
            {
                dp[i, 0] = dp[i - 1, 2];
                dp[i, 1] = dp[i - 1, 0];
                dp[i, 2] = dp[i - 1, 0] + dp[i - 1, 1];
            }

            Console.WriteLine(dp[N, 0] + dp[N, 1] + dp[N, 2]);
        }
    }

    public struct ModInt
    {
        public static int Mod = 1000000007;

        readonly long value;
        public int Value { get { return (int)value; } }
        public ModInt Inverse { get { return GetInverse(); } }

        public ModInt(long value)
        {
            value %= Mod;
            this.value = value < 0 ? value + Mod : value;
        }

        ModInt GetInverse()
        {
            if (value == 0) throw new InvalidOperationException("value must NOT equal 0");
            return Pow(Mod - 2);
        }

        public ModInt Square()
        {
            return this * this;
        }

        public ModInt Pow(long exp)
        {
            if (exp == 0) return 1;
            if (exp % 2 == 0) return Pow(exp / 2).Square();
            return this * Pow(exp - 1);
        }

        public static ModInt Parse(string str)
        {
            return long.Parse(str);
        }

        public static implicit operator ModInt(long value)
        {
            return new ModInt(value);
        }

        public static ModInt operator +(ModInt left, ModInt right)
        {
            return left.value + right.value;
        }

        public static ModInt operator -(ModInt left, ModInt right)
        {
            return left.value - right.value;
        }

        public static ModInt operator *(ModInt left, ModInt right)
        {
            return left.value * right.value;
        }

        public static ModInt operator /(ModInt left, ModInt right)
        {
            return left * right.Inverse;
        }

        public override bool Equals(object obj)
        {
            if (!(obj is ModInt)) return false;
            return value == ((ModInt)obj).value;
        }

        public override int GetHashCode()
        {
            return value.GetHashCode();
        }

        public override string ToString()
        {
            return value.ToString();
        }
    }
}
0