結果

問題 No.314 ケンケンパ
ユーザー bayashiko_rbayashiko_r
提出日時 2019-01-03 21:23:34
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 322 ms / 1,000 ms
コード長 1,418 bytes
コンパイル時間 2,309 ms
コンパイル使用メモリ 107,540 KB
実行使用メモリ 46,152 KB
最終ジャッジ日時 2023-08-15 15:14:36
合計ジャッジ時間 5,462 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 312 ms
43,816 KB
testcase_01 AC 53 ms
20,648 KB
testcase_02 AC 55 ms
21,276 KB
testcase_03 AC 54 ms
21,148 KB
testcase_04 AC 53 ms
20,732 KB
testcase_05 AC 52 ms
22,848 KB
testcase_06 AC 53 ms
21,148 KB
testcase_07 AC 54 ms
21,360 KB
testcase_08 AC 54 ms
21,168 KB
testcase_09 AC 54 ms
21,308 KB
testcase_10 AC 53 ms
21,140 KB
testcase_11 AC 54 ms
23,204 KB
testcase_12 AC 53 ms
21,140 KB
testcase_13 AC 55 ms
21,196 KB
testcase_14 AC 55 ms
21,148 KB
testcase_15 AC 56 ms
21,128 KB
testcase_16 AC 61 ms
23,204 KB
testcase_17 AC 82 ms
23,108 KB
testcase_18 AC 183 ms
31,900 KB
testcase_19 AC 322 ms
46,152 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class Program {
    static void Main(string[] args) {
        //入力
        ulong N = ulong.Parse(Console.ReadLine());
        //出力
        switch (N) {
            case 1:
                Console.WriteLine("1");
                break;
            case 2:
                Console.WriteLine("2");
                break;
            case 3:
                Console.WriteLine("2");
                break;
            default:
                //各係数に対する配列を用意する
                ulong[] an = new ulong[N];
                ulong[] bn = new ulong[N];
                ulong[] cn = new ulong[N];
                an[0] = 1;
                an[1] = 0;
                an[2] = 0;

                bn[0] = 0;
                bn[1] = 1;
                bn[2] = 0;

                cn[0] = 0;
                cn[1] = 0;
                cn[2] = 1;

                for (ulong i = 3; i < N; i++) {
                    an[i] = an[i - 3] + an[i - 2];
                    bn[i] = bn[i - 3] + bn[i - 2];
                    cn[i] = cn[i - 3] + cn[i - 2];
                    an[i] %= (uint)Math.Pow(10, 9) + 7;
                    bn[i] %= (uint)Math.Pow(10, 9) + 7;
                    cn[i] %= (uint)Math.Pow(10, 9) + 7;
                }
                Console.WriteLine((an[N - 1] + 2 * bn[N - 1] + 2 * cn[N - 1]) % (uint)(Math.Pow(10, 9) + 7));
                break;
        }
    }
}
0