結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
AreTrash
|
| 提出日時 | 2016-04-13 16:03:40 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,921 bytes |
| コンパイル時間 | 936 ms |
| コンパイル使用メモリ | 116,652 KB |
| 実行使用メモリ | 27,200 KB |
| 最終ジャッジ日時 | 2024-10-04 07:22:49 |
| 合計ジャッジ時間 | 7,840 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 TLE * 1 -- * 4 |
コンパイルメッセージ
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;
using System.Linq;
namespace No10_1{
public class Program{
public static int n = Read(Convert.ToInt32);
public static int total = Read(Convert.ToInt32);
public static List<int> an = ReadList(Convert.ToInt32);
public static List<int>[] dplist = new List<int>[n + 1];
public static Stack<bool> stk = new Stack<bool>();
public static bool flag = an.All(x => x <= 3);
public static void Main(string[] args){
for(var i = 0; i < dplist.Length; i++){
dplist[i] = new List<int>();
}
an.Insert(0, 0);
an.Add(int.MaxValue);
Solve(true, 0, 0);
stk.Pop();
stk.Pop();
var result = "";
foreach(var s in stk){
result += s ? "+" : "*";
}
Console.WriteLine(result);
Console.ReadLine();
}
public static bool Solve(bool op, int sum, int cnt){
if(sum == total && cnt == n + 1) return true;
if(sum > total || cnt > n) return false;
if(flag){
if(dplist[cnt].Contains(sum)) return false;
dplist[cnt].Add(sum);
}
if(Solve(true, sum + an[cnt], cnt + 1)){
stk.Push(true);
return true;
}
if(Solve(false, sum * an[cnt], cnt + 1)){
stk.Push(false);
return true;
}
return false;
}
public static TOutput Read<TOutput>(Converter<string, TOutput> converter){
return converter(Console.ReadLine());
}
public static List<TOutput> ReadList<TOutput>(Converter<string, TOutput> converter, char c = ' '){
return Console.ReadLine()?.Split(c).ToList().ConvertAll(converter);
}
}
}
AreTrash