結果

問題 No.258 回転寿司(2)
ユーザー 明智重蔵明智重蔵
提出日時 2016-07-02 16:55:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 2,919 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 109,952 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2024-04-24 11:19:56
合計ジャッジ時間 5,682 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
19,840 KB
testcase_01 AC 30 ms
19,584 KB
testcase_02 AC 28 ms
19,968 KB
testcase_03 AC 25 ms
19,328 KB
testcase_04 AC 29 ms
19,584 KB
testcase_05 AC 29 ms
19,712 KB
testcase_06 AC 30 ms
19,584 KB
testcase_07 AC 31 ms
19,712 KB
testcase_08 AC 30 ms
19,840 KB
testcase_09 AC 29 ms
19,456 KB
testcase_10 AC 26 ms
19,328 KB
testcase_11 AC 28 ms
19,840 KB
testcase_12 AC 28 ms
19,712 KB
testcase_13 AC 30 ms
19,456 KB
testcase_14 AC 30 ms
19,456 KB
testcase_15 AC 29 ms
19,584 KB
testcase_16 AC 29 ms
19,712 KB
testcase_17 AC 30 ms
19,584 KB
testcase_18 AC 29 ms
19,840 KB
testcase_19 AC 26 ms
19,200 KB
testcase_20 AC 29 ms
19,840 KB
testcase_21 AC 30 ms
19,712 KB
testcase_22 AC 26 ms
19,456 KB
testcase_23 AC 26 ms
19,456 KB
testcase_24 AC 26 ms
19,328 KB
testcase_25 AC 24 ms
19,328 KB
testcase_26 AC 31 ms
19,840 KB
testcase_27 AC 31 ms
19,584 KB
testcase_28 AC 32 ms
19,712 KB
testcase_29 AC 31 ms
19,456 KB
testcase_30 AC 27 ms
19,584 KB
testcase_31 AC 25 ms
19,328 KB
testcase_32 AC 30 ms
19,840 KB
testcase_33 AC 31 ms
19,584 KB
testcase_34 AC 31 ms
19,840 KB
testcase_35 AC 29 ms
19,712 KB
testcase_36 AC 29 ms
19,584 KB
testcase_37 AC 25 ms
19,328 KB
testcase_38 AC 31 ms
19,712 KB
testcase_39 AC 31 ms
19,712 KB
testcase_40 AC 30 ms
19,456 KB
testcase_41 AC 29 ms
19,840 KB
testcase_42 AC 29 ms
19,840 KB
testcase_43 AC 30 ms
19,712 KB
testcase_44 AC 31 ms
19,712 KB
testcase_45 AC 28 ms
19,712 KB
testcase_46 AC 27 ms
19,200 KB
testcase_47 AC 29 ms
19,712 KB
testcase_48 AC 29 ms
19,584 KB
testcase_49 AC 29 ms
19,584 KB
testcase_50 AC 27 ms
19,200 KB
testcase_51 AC 29 ms
19,840 KB
testcase_52 AC 30 ms
19,712 KB
testcase_53 AC 29 ms
19,712 KB
testcase_54 AC 29 ms
19,584 KB
testcase_55 AC 28 ms
19,840 KB
testcase_56 AC 28 ms
19,840 KB
testcase_57 AC 29 ms
19,584 KB
testcase_58 AC 28 ms
19,840 KB
testcase_59 AC 30 ms
19,712 KB
testcase_60 AC 25 ms
19,072 KB
testcase_61 AC 28 ms
19,584 KB
testcase_62 AC 29 ms
19,968 KB
testcase_63 AC 29 ms
19,712 KB
testcase_64 AC 29 ms
19,584 KB
testcase_65 AC 28 ms
19,840 KB
testcase_66 AC 24 ms
19,328 KB
testcase_67 AC 30 ms
19,712 KB
testcase_68 AC 31 ms
19,840 KB
testcase_69 AC 30 ms
19,712 KB
testcase_70 AC 28 ms
19,968 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;

//No.258 回転寿司(2)
class Program
{
    static string InputPattern = "InputX";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("1 2 3 4");
            //6
            //2 4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("5 4 4 9");
            //14
            //1 4
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("7");
            WillReturn.Add("1 2 9 10 1 1 4");
            //16
            //2 4 7
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("1");
            WillReturn.Add("100");
            //100
            //1
        }
        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);

        //最大の美味しさ合計[添字]なDP表
        var DPArr = new Nullable<int>[UB + 1];

        //配るDPでの配布元の添字
        int[] MotoIndArr = new int[UB + 1];
        for (int I = 0; I <= UB; I++) MotoIndArr[I] = -1;

        DPArr[0] = VArr[0];
        if (UB > 0) DPArr[1] = VArr[1];

        for (int I = 0; I <= UB; I++) {
            Action<int> UpdateAct = (pNewInd) =>
            {
                if (pNewInd > UB) return;
                int NewVal = DPArr[I].Value + VArr[pNewInd];

                if (DPArr[pNewInd].HasValue == false
                 || DPArr[pNewInd].Value < NewVal) {
                    DPArr[pNewInd] = NewVal;
                    MotoIndArr[pNewInd] = I;
                }
            };

            UpdateAct(I + 2);
            UpdateAct(I + 3);
            //for (int J = 0; J <= UB; J++) {
            //    Console.WriteLine("DPArr[{0}]={1}", J, DPArr[J]);
            //}
        }
        //UBかUB-1が最大値
        int MaxSumVal = DPArr[UB].Value;
        int CurrInd = UB;
        if (UB > 0 && DPArr[UB - 1].Value > MaxSumVal) {
            MaxSumVal = DPArr[UB - 1].Value;
            CurrInd = UB - 1;
        }
        Console.WriteLine(MaxSumVal);

        //DPの経路復元
        var IndList = new List<int>();
        while (CurrInd != -1) {
            IndList.Add(CurrInd);
            CurrInd = MotoIndArr[CurrInd];
        }
        var sb = new System.Text.StringBuilder();
        for (int I = IndList.Count - 1; 0 <= I; I--) {
            sb.Append(IndList[I] + 1);
            if (I > 0) sb.Append(' ');
        }
        Console.WriteLine(sb.ToString());
    }
}
0