結果

問題 No.505 カードの数式2
ユーザー 14番14番
提出日時 2017-04-21 22:58:33
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,979 bytes
コンパイル時間 5,215 ms
コンパイル使用メモリ 106,260 KB
実行使用メモリ 213,888 KB
最終ジャッジ日時 2023-09-27 12:25:12
合計ジャッジ時間 9,871 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
21,936 KB
testcase_01 AC 73 ms
21,912 KB
testcase_02 AC 90 ms
24,936 KB
testcase_03 AC 71 ms
22,000 KB
testcase_04 AC 72 ms
21,948 KB
testcase_05 AC 72 ms
23,984 KB
testcase_06 AC 71 ms
22,084 KB
testcase_07 AC 72 ms
24,068 KB
testcase_08 AC 71 ms
22,020 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 71 ms
21,984 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 72 ms
22,172 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 72 ms
21,876 KB
testcase_20 AC 73 ms
22,016 KB
testcase_21 AC 73 ms
21,952 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 559 ms
81,696 KB
testcase_28 TLE -
testcase_29 WA -
testcase_30 WA -
testcase_31 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.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