結果

問題 No.10 +か×か
ユーザー 14番14番
提出日時 2016-03-30 17:07:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 207 ms / 5,000 ms
コード長 2,386 bytes
コンパイル時間 2,632 ms
コンパイル使用メモリ 105,276 KB
実行使用メモリ 59,160 KB
最終ジャッジ日時 2023-08-21 06:18:18
合計ジャッジ時間 4,472 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,788 KB
testcase_01 AC 57 ms
20,880 KB
testcase_02 AC 57 ms
22,684 KB
testcase_03 AC 167 ms
59,156 KB
testcase_04 AC 64 ms
27,552 KB
testcase_05 AC 55 ms
18,768 KB
testcase_06 AC 207 ms
59,160 KB
testcase_07 AC 121 ms
39,968 KB
testcase_08 AC 69 ms
27,148 KB
testcase_09 AC 80 ms
33,596 KB
testcase_10 AC 56 ms
20,812 KB
testcase_11 AC 55 ms
20,700 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.Collections.Generic;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int numCount = int.Parse(Reader.ReadLine());
        this.Total = int.Parse(Reader.ReadLine());
        this.NumList = Reader.GetInt();
        this.dic = new string[Total + 1, NumList.Length];
        string ans = GetAns(1, NumList[0]);
        Console.WriteLine(ans);
    }
    
    private int[] NumList;
    private int Total;
    
    private char[] enzan = new char[] {'+', '*'};
    
    private string[,] dic;
    
    public String GetAns(int idx, int subTotal) {
        if(dic[subTotal,idx] != null) {
            return dic[subTotal,idx];
        }

       string ans = string.Empty;
       foreach (char c in enzan)
       {
           int tmp = subTotal;
           if(c == '+') {
               tmp += NumList[idx];
           } else
           {
               tmp *= NumList[idx];
           }
           if(idx == NumList.Length - 1) {
               if(tmp == Total) {
                   return c.ToString();
               }
           } else
           {
               if(tmp <= Total) {
                    string ret = this.GetAns(idx + 1, tmp);
                    if(ret != null && ret.Length > 0) {
                        return c.ToString() + ret;
                    }
                }
           }
       }
       dic[subTotal, idx] = ans;
       return ans;
    }

    public class Reader {
        private static String InitText = @"






        ";
        
        private static System.IO.StringReader sr = null;
        
        public static bool IsDebug = true;
        
        public static string ReadLine() {
            if(IsDebug) {
                if(sr == null) {
                    sr = new System.IO.StringReader(InitText.Trim());
                }
                return sr.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ') {
            string[] inpt = ReadLine().Split(delimiter);
            int[] ret = new int[inpt.Length];
            for(int i=0; i<inpt.Length; i++) {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0