結果

問題 No.220 世界のなんとか2
ユーザー 明智重蔵明智重蔵
提出日時 2017-01-28 16:30:59
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 52 ms / 1,000 ms
コード長 1,959 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 106,028 KB
実行使用メモリ 22,668 KB
最終ジャッジ日時 2023-08-25 13:14:02
合計ジャッジ時間 4,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
20,584 KB
testcase_01 AC 48 ms
18,608 KB
testcase_02 AC 47 ms
22,668 KB
testcase_03 AC 47 ms
20,700 KB
testcase_04 AC 47 ms
20,684 KB
testcase_05 AC 47 ms
22,640 KB
testcase_06 AC 47 ms
20,728 KB
testcase_07 AC 50 ms
20,716 KB
testcase_08 AC 49 ms
20,584 KB
testcase_09 AC 50 ms
20,632 KB
testcase_10 AC 46 ms
22,616 KB
testcase_11 AC 49 ms
18,724 KB
testcase_12 AC 52 ms
20,616 KB
testcase_13 AC 48 ms
20,608 KB
testcase_14 AC 48 ms
20,756 KB
testcase_15 AC 47 ms
20,704 KB
testcase_16 AC 48 ms
20,648 KB
testcase_17 AC 47 ms
18,580 KB
testcase_18 AC 46 ms
18,640 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;

//http://yukicoder.me/problems/no/220
//No.220 世界のなんとか2
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1");
            //3
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2");
            //45
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("19");
            //9099432188218005273
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int P = int.Parse(InputList[0]);

        //場合の数[3を法とした余り,3の有無]なDP表
        long[,] PrevDP = new long[3, 2];
        PrevDP[0, 0] = 1;

        for (int I = 1; I <= P; I++) {
            long[,] CurrDP = new long[3, 2];
            for (int J = 0; J <= PrevDP.GetUpperBound(0); J++) {
                for (int K = 0; K <= PrevDP.GetUpperBound(1); K++) {
                    if (PrevDP[J, K] == 0) continue;

                    for (int NewNum = 0; NewNum <= 9; NewNum++) {
                        int NewJ = (J + NewNum) % 3;

                        int NewK = K;
                        if (NewNum == 3) NewK = 1;

                        CurrDP[NewJ, NewK] += PrevDP[J, K];
                    }
                }
            }
            PrevDP = CurrDP;
        }
        long Answer = 0;
        for (int I = 0; I <= PrevDP.GetUpperBound(0); I++) {
            for (int J = 0; J <= PrevDP.GetUpperBound(1); J++) {
                if (I == 0 || J == 1) Answer += PrevDP[I, J];
            }
        }
        Answer--; //0の分
        Console.WriteLine(Answer);
    }
}
0