結果

問題 No.45 回転寿司
ユーザー 明智重蔵明智重蔵
提出日時 2015-07-25 19:56:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 2,183 bytes
コンパイル時間 4,282 ms
コンパイル使用メモリ 106,088 KB
実行使用メモリ 24,152 KB
最終ジャッジ日時 2023-08-27 14:10:28
合計ジャッジ時間 7,716 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
20,056 KB
testcase_01 AC 71 ms
20,076 KB
testcase_02 AC 72 ms
24,152 KB
testcase_03 AC 73 ms
20,096 KB
testcase_04 AC 71 ms
22,072 KB
testcase_05 AC 62 ms
21,892 KB
testcase_06 AC 72 ms
22,052 KB
testcase_07 AC 72 ms
22,036 KB
testcase_08 AC 70 ms
20,060 KB
testcase_09 AC 75 ms
22,120 KB
testcase_10 AC 73 ms
22,100 KB
testcase_11 AC 70 ms
21,956 KB
testcase_12 AC 73 ms
22,196 KB
testcase_13 AC 64 ms
21,920 KB
testcase_14 AC 64 ms
23,836 KB
testcase_15 AC 72 ms
24,108 KB
testcase_16 AC 71 ms
24,048 KB
testcase_17 AC 72 ms
24,032 KB
testcase_18 AC 72 ms
22,212 KB
testcase_19 AC 73 ms
22,196 KB
testcase_20 AC 65 ms
23,936 KB
testcase_21 AC 64 ms
21,964 KB
testcase_22 AC 64 ms
23,888 KB
testcase_23 AC 63 ms
21,816 KB
testcase_24 AC 63 ms
21,888 KB
testcase_25 AC 62 ms
22,008 KB
testcase_26 AC 70 ms
22,192 KB
testcase_27 AC 75 ms
19,964 KB
testcase_28 AC 72 ms
22,072 KB
testcase_29 AC 73 ms
22,108 KB
testcase_30 AC 72 ms
22,116 KB
testcase_31 AC 64 ms
21,944 KB
testcase_32 AC 63 ms
21,944 KB
testcase_33 AC 73 ms
22,028 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;

class Program
{
    static string InputPattern = "Input5";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("1 2 3 4");
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("5 4 4 9");
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("7");
            WillReturn.Add("1 2 9 10 1 1 4");
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("1");
            WillReturn.Add("100");
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] VArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
        int UB = VArr.GetUpperBound(0);

        //添字が皿の合計、値が美味しさ合計の最大値
        int[] SumVArr = new int[UB + 1];

        for (int I = 0; I <= UB; I++) {
            if (I == 0 || I == 1) {
                SumVArr[I] = VArr[I];
                continue;
            }

            //配列の添字の上限までの範囲での、最大値を返す
            Func<int, int> DeriveHaniMaxFunc = pJyougenInd =>
            {
                int WillReturn = SumVArr[0];
                for (int J = 0; J <= pJyougenInd; J++) {
                    if (WillReturn < SumVArr[J])
                        WillReturn = SumVArr[J];
                }
                return WillReturn;
            };

            //その皿を取るノードでの美味しさ合計の最大値
            int Node1SumV = DeriveHaniMaxFunc(I - 2) + VArr[I];
            //その皿を取らないノードでの美味しさ合計の最大値
            int Node2SumV = DeriveHaniMaxFunc(I - 1);

            SumVArr[I] = Math.Max(Node1SumV, Node2SumV);
        }
        Console.WriteLine(SumVArr.Max());
    }
}
0