結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
mban
|
| 提出日時 | 2016-11-10 16:53:25 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,669 bytes |
| コンパイル時間 | 788 ms |
| コンパイル使用メモリ | 113,276 KB |
| 実行使用メモリ | 356,172 KB |
| 最終ジャッジ日時 | 2024-11-25 07:14:17 |
| 合計ジャッジ時間 | 5,572 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 1 |
コンパイルメッセージ
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;
class Magatro
{
static int N;
static int Total;
static int[] A;
const int MAX = 100000;
static void Main()
{
Read();
string[,] ans = new string[N, MAX+1];
ans[1, A[0] + A[1]] = "+";
ans[1, A[0] * A[1]] = "*";
for (int j = 2; j < N; j++)
{
for (int i = 0; i <= MAX; i++)
{
if (ans[j-1, i] != null)
{
if (i * A[j] <= MAX)
{
ans[j, i * A[j]] = Min(ans[j - 1, i] + "*",ans[j,i*A[j]]);
}
if (i + A[j] <= MAX)
{
ans[j, i + A[j]] =Min( ans[j - 1, i] + "+", ans[j, i + A[j]]);
}
}
}
}
Console.WriteLine(ans[N - 1, Total]);
}
static void Read()
{
N = int.Parse(Console.ReadLine());
Total = int.Parse(Console.ReadLine());
A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
}
static string Min(string a,string b)
{
if (a == null)
{
return b;
}
if (b == null)
{
return a;
}
for(int i = 0; i < Math.Min(a.Length, b.Length); i++)
{
if (a[i] != b[i])
{
if (a[i] == '+')
{
return a;
}
else
{
return b;
}
}
}
return "Dummy";
}
}
mban