結果

問題 No.45 回転寿司
ユーザー 明智重蔵
提出日時 2015-07-25 19:56:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 2,183 bytes
コンパイル時間 3,085 ms
コンパイル使用メモリ 108,672 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-12-27 11:52:20
合計ジャッジ時間 5,519 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
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