結果
| 問題 |
No.555 世界史のレポート
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2017-08-11 23:16:01 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,488 bytes |
| コンパイル時間 | 1,092 ms |
| コンパイル使用メモリ | 110,132 KB |
| 実行使用メモリ | 25,116 KB |
| 最終ジャッジ日時 | 2024-10-12 21:49:39 |
| 合計ジャッジ時間 | 2,614 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program
{
public void Proc()
{
this.MustLength = int.Parse(Reader.ReadLine());
int[] tmp = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
this.CopyCost = tmp[0];
this.PasteCost = tmp[1];
this.MinCost = CopyCost;
this.MinCost += (MustLength - 1) * this.PasteCost;
long ans = GetAns(1, 1, CopyCost);
if(ans< 0) {
ans = MinCost;
}
Console.WriteLine(ans);
}
private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>();
private long GetAns(int copyLength, int reportLength, long subtotal) {
if (subtotal > MinCost)
{
return -1;
}
if(reportLength >= MustLength) {
this.MinCost = Math.Min(MinCost, subtotal);
return subtotal;
}
if(!dic.ContainsKey(copyLength)) {
dic.Add(copyLength, new Dictionary<int, long>());
}
if(dic[copyLength].ContainsKey(reportLength)) {
return dic[copyLength][reportLength];
}
long ans = ((MustLength - reportLength) / copyLength)*PasteCost + subtotal;
if((MustLength-reportLength)%copyLength>0) {
ans += PasteCost;
}
long ret = GetAns(copyLength + reportLength, copyLength + reportLength, subtotal + CopyCost + PasteCost);
if(ret >= 0) {
ans = Math.Min(ans, ret);
}
ret = GetAns(copyLength, reportLength + copyLength, subtotal + PasteCost);
if (ret >= 0)
{
ans = Math.Min(ans, ret);
}
if(ans > this.MinCost) {
ans = -1;
} else {
MinCost = ans;
}
dic[copyLength][reportLength] = ans;
return ans;
}
private long MinCost = 0;
private int MustLength;
private int CopyCost;
private int PasteCost;
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 = @"
10
1 3
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
14番