結果

問題 No.37 遊園地のアトラクション
ユーザー 明智重蔵
提出日時 2015-08-08 17:02:40
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 1,713 bytes
コンパイル時間 4,021 ms
コンパイル使用メモリ 116,304 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-10-10 13:02:54
合計ジャッジ時間 4,223 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 List<string> GetInputList()
    {
        var WillReturn = new List<string>();
        string wkStr;
        while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        return WillReturn;
    }

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

        //添字が時間の合計、値が満足度合計の最大値
        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].Value + VArr[LoopI];

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

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

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