結果

問題 No.37 遊園地のアトラクション
ユーザー 明智重蔵明智重蔵
提出日時 2015-07-21 19:26:03
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,693 bytes
コンパイル時間 2,272 ms
コンパイル使用メモリ 106,900 KB
実行使用メモリ 25,804 KB
最終ジャッジ日時 2023-09-22 20:57:19
合計ジャッジ時間 6,162 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 64 ms
21,724 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = "Input4";

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

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

    struct JyoutaiDef
    {
        internal int CurrP;
        internal int CSum;
        internal int VSum;
        internal int[] CurrVArr;
        internal string Path;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int T = int.Parse(InputList[0]);
        int[] CArr = InputList[2].Split(' ').Select(X => int.Parse(X)).ToArray();
        int[] VArr = InputList[3].Split(' ').Select(X => int.Parse(X)).ToArray();
        int UB = CArr.GetUpperBound(0);

        var stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.CurrP = 0;
        WillPush.CSum = 0;
        WillPush.VSum = 0;
        WillPush.CurrVArr = VArr;
        WillPush.Path = "";
        stk.Push(WillPush);

        int AnswerVSum = 0;
        string AnswerPath = "";

        while (stk.Count > 0) {
            JyoutaiDef Popped = stk.Pop();
            //Console.WriteLine("満足度合計={0}", Popped.VSum);
            //Console.WriteLine(Popped.Path);

            //解の更新
            if (AnswerVSum < Popped.VSum) {
                AnswerVSum = Popped.VSum;
                AnswerPath = Popped.Path;
            }

            for (int I = Popped.CurrP; I <= UB; I++) {
                //対象アトラクションの満足度が0ならContinue;
                int CurrV = Popped.CurrVArr[I];
                if (CurrV == 0) continue;

                //Push処理
                WillPush.CurrP = I;
                WillPush.CSum = Popped.CSum + CArr[I];
                if (WillPush.CSum > T) continue;
                WillPush.VSum = Popped.VSum + CurrV;
                WillPush.CurrVArr = (int[])Popped.CurrVArr.Clone();
                WillPush.CurrVArr[I] /= 2; //満足度の更新
                WillPush.Path = Popped.Path + Environment.NewLine +
                    string.Format("アトラクション{0}(満足度{1})", I, CurrV);

                //下限値枝切り
                int RestSum = WillPush.VSum;
                for (int J = WillPush.CurrP; J <= UB; J++) {
                    int wkV = WillPush.CurrVArr[J];
                    while (true) {
                        RestSum += wkV;
                        if ((wkV /= 2) == 0) break;
                    }
                }
                if (RestSum < AnswerVSum) continue;

                stk.Push(WillPush);
            }
        }
        //Console.WriteLine("最大満足度={0}", AnswerVSum);
        //Console.WriteLine(AnswerPath);
        Console.WriteLine(AnswerVSum);
    }
}
0