結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
AreTrash
|
| 提出日時 | 2016-04-13 15:21:04 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,487 bytes |
| コンパイル時間 | 988 ms |
| コンパイル使用メモリ | 111,464 KB |
| 実行使用メモリ | 30,768 KB |
| 最終ジャッジ日時 | 2024-10-04 07:20:25 |
| 合計ジャッジ時間 | 7,706 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.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 Stack<bool> stk = new Stack<bool>();
public static void Main(string[] args){
an.Insert(0, 0);
Solve(true, 0, 0);
stk.Pop();
stk.Pop();
var result = "";
foreach(var s in stk){
result += s ? "+" : "*";
}
Console.WriteLine(result);
}
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(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