結果

問題 No.504 ゲーム大会(ランキング)
ユーザー 14番14番
提出日時 2017-04-21 22:58:18
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 1,979 bytes
コンパイル時間 2,611 ms
コンパイル使用メモリ 107,752 KB
実行使用メモリ 23,792 KB
最終ジャッジ日時 2023-09-27 12:24:48
合計ジャッジ時間 4,117 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        this.ItemCount = int.Parse(Reader.ReadLine());

        this.Items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        decimal ans = GetAns(1, this.Items[0]);
        ans = Math.Max(ans, GetAns(1, this.Items[0] * -1));
        Console.WriteLine(ans);

    }
    private int[] Items;
    private int ItemCount = 0;
    private Dictionary<int, Dictionary<decimal, decimal>> dic = new Dictionary<int, Dictionary<decimal, decimal>>();
    private decimal GetAns(int idx, decimal subTotal)
    {
        if (idx >= ItemCount)
        {
            return subTotal;
        }

        if (!dic.ContainsKey(idx))
        {
            dic.Add(idx, new Dictionary<decimal, decimal>());
        }
        if (dic[idx].ContainsKey(subTotal))
        {
            return dic[idx][subTotal];
        }

        decimal ans = 0;

        int num = Items[idx];

        ans = GetAns(idx + 1, subTotal + num);
        ans = Math.Max(ans, GetAns(idx + 1, subTotal - num));
        ans = Math.Max(ans, GetAns(idx + 1, subTotal * num));
        dic[idx][subTotal] = ans;
        return ans;

    }




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


16
6 9 1 2 1 2 1 2 1 4 1 4 1 8 1 2



";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0