結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
AreTrash
|
| 提出日時 | 2016-04-14 03:07:58 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 1,527 ms / 5,000 ms |
| コード長 | 1,760 bytes |
| コンパイル時間 | 993 ms |
| コンパイル使用メモリ | 110,360 KB |
| 実行使用メモリ | 347,776 KB |
| 最終ジャッジ日時 | 2024-12-14 15:35:42 |
| 合計ジャッジ時間 | 5,329 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
コンパイルメッセージ
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_3{
public class Program{
public static void Main(string[] args){
var n = Read(Convert.ToInt32);
var total = Read(Convert.ToInt32);
var an = ReadList(Convert.ToInt32);
var dpAry = new string[n + 1, total + 1];
if(an[0] * an[1] <= total)
dpAry[1, an[0] * an[1]] = "*";
if(an[0] + an[1] <= total)
dpAry[1, an[0] + an[1]] = "+";
for(var i = 2; i < n; i++){
for(var j = 1; j <= total; j++){
if(dpAry[i - 1, j] != null){
if(j * an[i] <= total){
if(dpAry[i, j * an[i]] == null ||
string.CompareOrdinal(dpAry[i, j * an[i]], dpAry[i - 1, j] + "*") < 0)
dpAry[i, j * an[i]] = dpAry[i - 1, j] + "*";
}
if(j + an[i] <= total){
if(dpAry[i, j + an[i]] == null ||
string.CompareOrdinal(dpAry[i, j + an[i]], dpAry[i - 1, j] + "+") < 0)
dpAry[i, j + an[i]] = dpAry[i - 1, j] + "+";
}
}
}
}
Console.WriteLine(dpAry[n - 1, total]);
}
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