結果

問題 No.45 回転寿司
ユーザー 明智重蔵明智重蔵
提出日時 2015-07-25 20:21:34
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 481 ms / 5,000 ms
コード長 2,128 bytes
コンパイル時間 2,953 ms
コンパイル使用メモリ 107,944 KB
実行使用メモリ 24,192 KB
最終ジャッジ日時 2023-08-27 14:12:24
合計ジャッジ時間 9,913 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
22,068 KB
testcase_01 AC 155 ms
22,092 KB
testcase_02 AC 266 ms
22,144 KB
testcase_03 AC 393 ms
22,172 KB
testcase_04 AC 169 ms
22,208 KB
testcase_05 AC 66 ms
22,012 KB
testcase_06 AC 170 ms
22,124 KB
testcase_07 AC 279 ms
22,236 KB
testcase_08 AC 89 ms
22,120 KB
testcase_09 AC 270 ms
22,192 KB
testcase_10 AC 111 ms
22,072 KB
testcase_11 AC 82 ms
22,236 KB
testcase_12 AC 376 ms
22,172 KB
testcase_13 AC 66 ms
21,920 KB
testcase_14 AC 65 ms
22,044 KB
testcase_15 AC 117 ms
22,108 KB
testcase_16 AC 91 ms
24,192 KB
testcase_17 AC 113 ms
22,016 KB
testcase_18 AC 91 ms
22,076 KB
testcase_19 AC 258 ms
24,012 KB
testcase_20 AC 66 ms
21,840 KB
testcase_21 AC 67 ms
22,028 KB
testcase_22 AC 65 ms
23,928 KB
testcase_23 AC 66 ms
21,816 KB
testcase_24 AC 66 ms
21,840 KB
testcase_25 AC 65 ms
21,948 KB
testcase_26 AC 143 ms
22,112 KB
testcase_27 AC 233 ms
24,092 KB
testcase_28 AC 153 ms
22,112 KB
testcase_29 AC 236 ms
22,012 KB
testcase_30 AC 173 ms
22,192 KB
testcase_31 AC 65 ms
24,004 KB
testcase_32 AC 65 ms
21,868 KB
testcase_33 AC 481 ms
22,240 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;
    }

    struct JyoutaiDef
    {
        internal int CurrP;
        internal int SumVal;
    }

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

        var stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.CurrP = 0;
        WillPush.SumVal = 0;
        stk.Push(WillPush);

        int Answer = 0;

        //メモ化探索用
        var MemoDict = new Dictionary<int, int>();

        while (stk.Count > 0) {
            JyoutaiDef Popped = stk.Pop();
            if (Answer < Popped.SumVal)
                Answer = Popped.SumVal;

            for (int I = Popped.CurrP; I <= UB && I <= Popped.CurrP + 1; I++) {
                WillPush.CurrP = I + 2;
                WillPush.SumVal = Popped.SumVal + VArr[I];

                if (MemoDict.ContainsKey(WillPush.CurrP)) {
                    if (MemoDict[WillPush.CurrP] >= WillPush.SumVal)
                        continue;
                }
                MemoDict[WillPush.CurrP] = WillPush.SumVal;

                stk.Push(WillPush);
            }
        }
        Console.WriteLine(Answer);
    }
}
0