結果

問題 No.505 カードの数式2
ユーザー 14番14番
提出日時 2017-04-21 22:53:03
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,888 bytes
コンパイル時間 4,671 ms
コンパイル使用メモリ 107,040 KB
実行使用メモリ 98,292 KB
最終ジャッジ日時 2023-09-27 12:19:12
合計ジャッジ時間 7,456 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,740 KB
testcase_01 AC 61 ms
21,700 KB
testcase_02 AC 68 ms
24,828 KB
testcase_03 AC 59 ms
21,700 KB
testcase_04 AC 58 ms
21,680 KB
testcase_05 AC 60 ms
21,708 KB
testcase_06 AC 60 ms
23,724 KB
testcase_07 AC 60 ms
21,552 KB
testcase_08 AC 61 ms
21,656 KB
testcase_09 AC 62 ms
21,700 KB
testcase_10 AC 58 ms
23,648 KB
testcase_11 WA -
testcase_12 AC 59 ms
21,676 KB
testcase_13 AC 62 ms
23,668 KB
testcase_14 AC 59 ms
21,656 KB
testcase_15 AC 58 ms
21,632 KB
testcase_16 AC 60 ms
21,568 KB
testcase_17 WA -
testcase_18 AC 61 ms
23,624 KB
testcase_19 AC 62 ms
21,760 KB
testcase_20 AC 60 ms
23,620 KB
testcase_21 AC 60 ms
23,776 KB
testcase_22 WA -
testcase_23 AC 79 ms
28,200 KB
testcase_24 AC 63 ms
23,752 KB
testcase_25 AC 60 ms
21,720 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 62 ms
21,804 KB
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();

        long ans = GetAns(1, this.Items[0]);
        Console.WriteLine(ans);

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

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

        long 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