結果

問題 No.37 遊園地のアトラクション
ユーザー 明智重蔵明智重蔵
提出日時 2015-07-25 18:19:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 2,742 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 108,928 KB
実行使用メモリ 20,608 KB
最終ジャッジ日時 2024-04-18 19:40:44
合計ジャッジ時間 4,191 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
20,096 KB
testcase_01 AC 27 ms
20,224 KB
testcase_02 AC 27 ms
20,224 KB
testcase_03 AC 27 ms
20,352 KB
testcase_04 AC 27 ms
20,224 KB
testcase_05 AC 30 ms
20,480 KB
testcase_06 AC 27 ms
20,480 KB
testcase_07 AC 33 ms
20,608 KB
testcase_08 AC 30 ms
20,352 KB
testcase_09 AC 26 ms
20,608 KB
testcase_10 AC 29 ms
20,224 KB
testcase_11 AC 29 ms
20,352 KB
testcase_12 AC 30 ms
20,480 KB
testcase_13 AC 29 ms
20,352 KB
testcase_14 AC 29 ms
20,608 KB
testcase_15 AC 29 ms
20,608 KB
testcase_16 AC 28 ms
20,352 KB
testcase_17 AC 30 ms
20,224 KB
testcase_18 AC 30 ms
20,480 KB
testcase_19 AC 30 ms
20,352 KB
testcase_20 AC 28 ms
20,480 KB
testcase_21 AC 28 ms
20,352 KB
testcase_22 AC 29 ms
20,092 KB
testcase_23 AC 25 ms
20,352 KB
testcase_24 AC 27 ms
20,096 KB
testcase_25 AC 27 ms
20,480 KB
testcase_26 AC 27 ms
20,096 KB
testcase_27 AC 28 ms
20,608 KB
testcase_28 AC 26 ms
20,096 KB
testcase_29 AC 26 ms
20,352 KB
testcase_30 AC 24 ms
20,608 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("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;
    }

    static void Main()
    {
        var sw = System.Diagnostics.Stopwatch.StartNew();

        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();

        //添字が時間の合計、値が満足度合計の最大値
        var SumVArr = new Nullable<int>[T + 1];
        SumVArr[0] = 0;

        int KasanValue = 0;
        for (int LoopI = 0; LoopI <= CArr.GetUpperBound(0); LoopI += KasanValue) {
            for (int LoopJ = T; 0 <= LoopJ; LoopJ--) {
                //時間制限を超えてしまう場合
                int wkSumC = LoopJ + CArr[LoopI];
                if (wkSumC > T) continue;

                //満足度の和を求める
                if (SumVArr[LoopJ] == null) continue;
                int wkSumV = (SumVArr[LoopJ] ?? 0) + VArr[LoopI];

                //満足度合計での最大の満足度を更新可能かを判定
                bool CanUpdate = false;
                if (SumVArr[wkSumC] == null) CanUpdate = true;
                else if (SumVArr[wkSumC] < wkSumV) CanUpdate = true;
                if (CanUpdate) {
                    SumVArr[wkSumC] = wkSumV;
                }
            }

            //同じアトラクションに乗った場合は、満足度は半分
            VArr[LoopI] /= 2;
            KasanValue = (VArr[LoopI] == 0 ? 1 : 0); 
        }

        Console.WriteLine(SumVArr.Max(X => X ?? 0));
    }
}
0