結果

問題 No.555 世界史のレポート
ユーザー 14番14番
提出日時 2017-08-11 23:16:01
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,488 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 108,416 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-04-20 23:31:45
合計ジャッジ時間 2,485 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
19,072 KB
testcase_01 AC 28 ms
19,200 KB
testcase_02 AC 28 ms
19,072 KB
testcase_03 AC 28 ms
19,200 KB
testcase_04 AC 28 ms
19,328 KB
testcase_05 AC 28 ms
19,200 KB
testcase_06 AC 28 ms
19,456 KB
testcase_07 AC 29 ms
19,328 KB
testcase_08 AC 30 ms
19,456 KB
testcase_09 AC 28 ms
19,328 KB
testcase_10 AC 30 ms
19,584 KB
testcase_11 AC 28 ms
19,456 KB
testcase_12 AC 28 ms
19,584 KB
testcase_13 AC 29 ms
19,584 KB
testcase_14 WA -
testcase_15 AC 30 ms
19,328 KB
testcase_16 AC 30 ms
19,584 KB
testcase_17 AC 28 ms
19,456 KB
testcase_18 AC 28 ms
19,584 KB
testcase_19 AC 28 ms
19,456 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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();
	}
}
0