結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-03-30 16:44:48 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,425 bytes |
| コンパイル時間 | 1,079 ms |
| コンパイル使用メモリ | 115,356 KB |
| 実行使用メモリ | 493,696 KB |
| 最終ジャッジ日時 | 2024-10-02 08:14:03 |
| 合計ジャッジ時間 | 7,593 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 8 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
string ans = GetAns(1, NumList[0]);
Console.WriteLine(ans);
}
private int[] NumList;
private int Total;
private char[] enzan = new char[] {'+', '*'};
private Dictionary<int, Dictionary<int, String>> dic = new Dictionary<int, Dictionary<int, string>>();
public String GetAns(int idx, int subTotal) {
if(!dic.ContainsKey(idx)) {
dic.Add(idx, new Dictionary<int, String>());
}
if(dic[idx].ContainsKey(subTotal)) {
return dic[idx][subTotal];
}
string ans = null;
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
{
string ret = this.GetAns(idx + 1, tmp);
if(ret != null) {
return c.ToString() + ret;
}
}
}
dic[idx].Add(subTotal, ans);
return ans;
}
public class Reader {
private static String InitText = @"
3
2
1 1 2
";
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();
}
}
14番