結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2017-06-26 21:50:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,120 bytes |
コンパイル時間 | 1,017 ms |
コンパイル使用メモリ | 117,092 KB |
実行使用メモリ | 29,764 KB |
最終ジャッジ日時 | 2024-10-04 09:51:52 |
合計ジャッジ時間 | 7,684 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 TLE * 1 -- * 7 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 = long.Parse(Reader.ReadLine()); this.Items = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); List<char> ans = GetAns(0, Items[0]); Console.WriteLine(string.Join(string.Empty, ans)); } private long[] Items; private long Total; Dictionary<int, Dictionary<long, List<char>>> dic = new Dictionary<int, Dictionary<long, List<char>>>(); private List<char> GetAns(int idx, long subTotal) { if(subTotal>Total) { return null; } if(idx == Items.Length - 1) { if(subTotal == Total) { return new List<char>(); } else { return null; } } if(!dic.ContainsKey(idx)) { dic.Add(idx, new Dictionary<long, List<char>>()); } if(dic[idx].ContainsKey(subTotal)) { return dic[idx][subTotal]; } List<char> ans = new List<char>(); List<char> ret = GetAns(idx + 1, subTotal + Items[idx + 1]); if(ret != null) { ans.Add('+'); ans.AddRange(ret); dic[idx][subTotal] = ans; return ans; } ret = GetAns(idx + 1, subTotal * Items[idx + 1]); if (ret != null) { ans.Add('*'); ans.AddRange(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(); } }