結果

問題 No.555 世界史のレポート
ユーザー 明智重蔵明智重蔵
提出日時 2017-08-18 12:50:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 844 ms / 2,000 ms
コード長 5,650 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 114,816 KB
実行使用メモリ 49,300 KB
最終ジャッジ日時 2024-04-22 15:45:24
合計ジャッジ時間 8,632 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,336 KB
testcase_01 AC 30 ms
27,676 KB
testcase_02 AC 30 ms
23,476 KB
testcase_03 AC 31 ms
23,352 KB
testcase_04 AC 32 ms
27,672 KB
testcase_05 AC 33 ms
25,416 KB
testcase_06 AC 33 ms
25,612 KB
testcase_07 AC 34 ms
25,624 KB
testcase_08 AC 34 ms
25,228 KB
testcase_09 AC 36 ms
25,464 KB
testcase_10 AC 549 ms
49,300 KB
testcase_11 AC 625 ms
47,544 KB
testcase_12 AC 539 ms
47,124 KB
testcase_13 AC 463 ms
47,268 KB
testcase_14 AC 610 ms
48,168 KB
testcase_15 AC 621 ms
47,960 KB
testcase_16 AC 505 ms
49,016 KB
testcase_17 AC 583 ms
45,776 KB
testcase_18 AC 642 ms
47,860 KB
testcase_19 AC 844 ms
47,412 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.Collections.Generic;
using System.Linq;

//YukiCoder No.555 世界史のレポート
//https://yukicoder.me/problems/no/555
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6");
            WillReturn.Add("3 2");
            //12
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("10");
            WillReturn.Add("1 3");
            //15
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("100");
            WillReturn.Add("1000 1");
            //1099
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("35344");
            WillReturn.Add("768 919");
            //25141
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        int N = wkArr[0];

        SplitAct(InputList[1]);
        int C = wkArr[0];
        int V = wkArr[1];

        //最小コスト[レポートの文字数,クリップボートの文字数]なDP表
        var PrevDP = new Dictionary<long, int>();
        PrevDP.Add(100000, 0);

        int Answer = int.MaxValue;

        while (true) {
            bool WillBreak = true;
            var CurrDP = new Dictionary<long, int>();

            foreach (var EachPair in PrevDP) {
                JyoutaiDef CurrJyoutai = DeriveJyoutai(EachPair.Key);

                if (CurrJyoutai.ReportLen >= N) {
                    if (Answer > EachPair.Value)
                        Answer = EachPair.Value;
                    continue;
                }
                WillBreak = false;

                JyoutaiDef NewJyoutai;
                long NewKey;
                int NewValue;

                //コピーする場合
                if (CurrJyoutai.ClipLen < CurrJyoutai.ReportLen) {
                    NewJyoutai.ReportLen = CurrJyoutai.ReportLen;
                    NewJyoutai.ClipLen = CurrJyoutai.ReportLen;
                    NewKey = DeriveHash(NewJyoutai);
                    NewValue = EachPair.Value + C;
                    if (CurrDP.ContainsKey(NewKey) == false ||
                        CurrDP[NewKey] > NewValue) {
                        CurrDP[NewKey] = NewValue;
                    }
                }

                //ペーストする場合
                if (CurrJyoutai.ClipLen > 0) {
                    NewJyoutai.ReportLen = CurrJyoutai.ReportLen + CurrJyoutai.ClipLen;
                    NewJyoutai.ClipLen = CurrJyoutai.ClipLen;
                    NewKey = DeriveHash(NewJyoutai);
                    NewValue = EachPair.Value + V;
                    if (CurrDP.ContainsKey(NewKey) == false ||
                        CurrDP[NewKey] > NewValue) {
                        CurrDP[NewKey] = NewValue;
                    }
                }
            }
            PrevDP = CurrDP;
            if (WillBreak) break;
        }
        Console.WriteLine(Answer);

        ////最小コスト[レポートの文字数,クリップボートの文字数]なDP表
        //var DPArr = new Nullable<int>[N + 1, N + 1];
        //DPArr[1, 0] = 0;

        //for (int I = 0; I <= N; I++) {
        //    for (int J = 0; J <= N; J++) {
        //        if (DPArr[I, J].HasValue == false) continue;

        //        //コピーする場合
        //        int NewI = I;
        //        int NewJ = I;
        //        int NewCost = DPArr[I, J].Value + C;

        //        if (NewI > N) NewI = N;
        //        if (NewJ > N) NewJ = N;

        //        if (DPArr[NewI, NewJ].HasValue == false
        //        || DPArr[NewI, NewJ].Value > NewCost) {
        //            DPArr[NewI, NewJ] = NewCost;
        //        }

        //        //ペーストする場合
        //        NewI = I + J;
        //        NewJ = J;
        //        NewCost = DPArr[I, J].Value + V;

        //        if (NewI > N) NewI = N;
        //        if (NewJ > N) NewJ = N;

        //        if (DPArr[NewI, NewJ].HasValue == false
        //        || DPArr[NewI, NewJ].Value > NewCost) {
        //            DPArr[NewI, NewJ] = NewCost;
        //        }
        //    }
        //}
        ////for (int I = 0; I <= N; I++) {
        ////    for (int J = 0; J <= N; J++) {
        ////        Console.WriteLine("DPArr[{0},{1}]={2}", I, J, DPArr[I, J]);
        ////    }
        ////}

        //int Answer = int.MaxValue;
        //for (int I = 0; I <= N; I++) {
        //    if (DPArr[N, I].HasValue == false) continue;
        //    if (Answer > DPArr[N, I].Value)
        //        Answer = DPArr[N, I].Value;
        //}
        //Console.WriteLine(Answer);
    }

    struct JyoutaiDef
    {
        internal int ReportLen;
        internal int ClipLen;
    }

    static long DeriveHash(JyoutaiDef pJyoutai)
    {
        long WillReturn = 0;
        WillReturn += pJyoutai.ClipLen;
        WillReturn += (long)pJyoutai.ReportLen * 100000;
        return WillReturn;
    }

    static JyoutaiDef DeriveJyoutai(long pHash)
    {
        JyoutaiDef WillReturn;
        WillReturn.ClipLen = (int)(pHash % 100000);
        WillReturn.ReportLen = (int)(pHash / 100000);
        return WillReturn;
    }
}
0