結果

問題 No.10 +か×か
ユーザー バカらっくバカらっく
提出日時 2017-06-27 07:39:51
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,945 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 106,848 KB
実行使用メモリ 62,168 KB
最終ジャッジ日時 2023-07-27 14:49:07
合計ジャッジ時間 9,327 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,836 KB
testcase_01 AC 62 ms
21,600 KB
testcase_02 AC 62 ms
21,768 KB
testcase_03 AC 116 ms
62,168 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int itemCount = int.Parse(Reader.ReadLine());
        this.dic = new string[itemCount][];
        this.Total = long.Parse(Reader.ReadLine());
        this.Items = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        string ans = GetAns(0, Items[0]);
        Console.WriteLine(ans);
    }

    private long[] Items;

    private long Total;

    string[][] dic;

    private string GetAns(int idx, long subTotal) {
        if(subTotal>Total) {
            return null;
        }
        if(idx == Items.Length - 1) {
            if(subTotal == Total) {
                return "";
            } else {
                return null;
            }
        }
        if(dic[idx] == null) {
            dic[idx] = new string[this.Total + 1];
        }
        if(dic[idx][Total] != null) {
            return dic[idx][subTotal];
        }
        string ans = null;
        string ret = GetAns(idx + 1, subTotal + Items[idx + 1]);
        if(ret != null) {
            ans = "+" + ret;
            dic[idx][subTotal] = ans;
            return ans;
        }
        ret = GetAns(idx + 1, subTotal * Items[idx + 1]);
		if (ret != null)
		{
            ans = "*" + ret;
			dic[idx][subTotal] = ans;
			return ans;
		}
        return null;

	}

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



4
31
1 2 10 1





";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}
0