結果

問題 No.149 碁石の移動
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-16 17:53:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 2,869 bytes
コンパイル時間 3,220 ms
コンパイル使用メモリ 106,108 KB
実行使用メモリ 23,952 KB
最終ジャッジ日時 2023-08-25 17:37:35
合計ジャッジ時間 4,347 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
19,944 KB
testcase_01 AC 63 ms
23,844 KB
testcase_02 AC 64 ms
23,856 KB
testcase_03 AC 62 ms
21,812 KB
testcase_04 AC 64 ms
23,808 KB
testcase_05 AC 62 ms
23,796 KB
testcase_06 AC 62 ms
23,876 KB
testcase_07 AC 64 ms
21,900 KB
testcase_08 AC 63 ms
19,800 KB
testcase_09 AC 64 ms
23,852 KB
testcase_10 AC 63 ms
21,928 KB
testcase_11 AC 63 ms
23,856 KB
testcase_12 AC 61 ms
21,996 KB
testcase_13 AC 62 ms
21,800 KB
testcase_14 AC 61 ms
21,808 KB
testcase_15 AC 61 ms
21,904 KB
testcase_16 AC 62 ms
23,952 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;

class Program
{
    static string InputPattern = "Input5";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("2 1");
            WillReturn.Add("1 2");
            WillReturn.Add("2 3");
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2 0");
            WillReturn.Add("0 3");
            WillReturn.Add("2 1");
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("3 0");
            WillReturn.Add("2 3");
            WillReturn.Add("0 5");
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("43682 82641");
            WillReturn.Add("54647 3647");
            WillReturn.Add("92674 64591");
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = { };
        Action<int> SplitAct = (pIndY) =>
            wkArr = InputList[pIndY].Split(' ').Select(X => int.Parse(X)).ToArray();

        int ACntWhite, ACntBlack;
        int BCntWhite, BCntBlack;
        int TakeCntFromA, TakeCntFromB;

        SplitAct(0); ACntWhite = wkArr[0]; ACntBlack = wkArr[1];
        SplitAct(1); BCntWhite = wkArr[0]; BCntBlack = wkArr[1];
        SplitAct(2); TakeCntFromA = wkArr[0]; TakeCntFromB = wkArr[1];

        Action DebugPrintAct = () =>
        {
            //Console.WriteLine(new string('■', 20));
            //Console.WriteLine("袋Aの白={0}、黒={1}。袋Bの白={2}、黒={3}",
            //    ACntWhite, ACntBlack, BCntWhite, BCntBlack);
        };

        DebugPrintAct();

        //Aの袋からBの袋への移動
        if (TakeCntFromA <= ACntBlack) {
            ACntBlack -= TakeCntFromA;
            BCntBlack += TakeCntFromA;
        }
        else {
            int FirstMoveCnt = ACntBlack;
            ACntBlack = 0;
            BCntBlack += FirstMoveCnt;
            int SecondMoveCnt = TakeCntFromA - FirstMoveCnt;
            ACntWhite -= SecondMoveCnt;
            BCntWhite += SecondMoveCnt;
        }

        DebugPrintAct();

        //Bの袋からAの袋への移動
        if (TakeCntFromB <= BCntWhite) {
            BCntWhite -= TakeCntFromB;
            ACntWhite += TakeCntFromB;
        }
        else {
            int FirstMoveCnt = BCntWhite;
            BCntWhite = 0;
            ACntWhite += FirstMoveCnt;
            int SecondMoveCnt = TakeCntFromB - FirstMoveCnt;
            BCntBlack -= SecondMoveCnt;
            ACntBlack += SecondMoveCnt;
        }

        DebugPrintAct();

        Console.WriteLine(ACntWhite);
    }
}
0