結果

問題 No.10 +か×か
ユーザー バカらっくバカらっく
提出日時 2017-06-28 01:02:32
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 1,930 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 113,100 KB
実行使用メモリ 67,740 KB
最終ジャッジ日時 2024-04-15 02:48:44
合計ジャッジ時間 1,778 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
27,536 KB
testcase_01 AC 27 ms
23,224 KB
testcase_02 AC 27 ms
27,284 KB
testcase_03 RE -
testcase_04 AC 52 ms
53,532 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 27 ms
25,020 KB
testcase_11 AC 26 ms
25,144 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Total = int.Parse(Reader.ReadLine());

        this.Items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        dic = new string[this.Items.Length][];
        string ans = GetAns(1, Items[0]);
        Console.WriteLine(ans);
    }

    private int Total;

    private int[] Items;

    private string[][] dic;
    private string GetAns(int idx, int subtotal) {
        if(subtotal > Total) {
            return null;
        }
        if(idx>=this.Items.Length-1) {
            if(subtotal+Items[idx]==Total) {
                return "+";
            }
			if (subtotal * Items[idx] == Total)
			{
				return "*";
			}
            return string.Empty;
		}

        if(dic[idx] == null) {
            dic[idx] = new string[Total + 1];
        }
        if(dic[idx][subtotal] != null) {
            return dic[idx][subtotal];
        }

        string ans = null;
        ans = GetAns(idx+1, subtotal + Items[idx]);
        if(ans.Length > 0) {
            return "+" + ans;
        }
        ans = GetAns(idx + 1, subtotal * Items[idx]);
		if (ans.Length > 0)
		{
			return "*" + ans;
		}

        dic[idx][subtotal] = string.Empty;
        return string.Empty;
	}


    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