結果

問題 No.91 赤、緑、青の石
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-18 05:09:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 3,502 ms / 5,000 ms
コード長 3,148 bytes
コンパイル時間 4,264 ms
コンパイル使用メモリ 107,852 KB
実行使用メモリ 28,164 KB
最終ジャッジ日時 2023-09-06 12:15:03
合計ジャッジ時間 39,098 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,414 ms
25,896 KB
testcase_01 AC 1,591 ms
28,108 KB
testcase_02 AC 1,047 ms
28,000 KB
testcase_03 AC 1,807 ms
26,048 KB
testcase_04 AC 902 ms
28,052 KB
testcase_05 AC 2,126 ms
28,060 KB
testcase_06 AC 543 ms
28,164 KB
testcase_07 AC 62 ms
21,936 KB
testcase_08 AC 63 ms
23,988 KB
testcase_09 AC 63 ms
21,916 KB
testcase_10 AC 63 ms
23,932 KB
testcase_11 AC 647 ms
26,052 KB
testcase_12 AC 1,974 ms
27,928 KB
testcase_13 AC 2,178 ms
28,148 KB
testcase_14 AC 1,455 ms
28,148 KB
testcase_15 AC 2,285 ms
25,888 KB
testcase_16 AC 63 ms
23,912 KB
testcase_17 AC 63 ms
23,856 KB
testcase_18 AC 63 ms
19,884 KB
testcase_19 AC 62 ms
21,944 KB
testcase_20 AC 64 ms
19,868 KB
testcase_21 AC 64 ms
21,924 KB
testcase_22 AC 63 ms
21,888 KB
testcase_23 AC 62 ms
21,968 KB
testcase_24 AC 63 ms
21,796 KB
testcase_25 AC 3,502 ms
23,932 KB
testcase_26 AC 3,308 ms
27,944 KB
testcase_27 AC 64 ms
23,852 KB
testcase_28 AC 277 ms
26,052 KB
testcase_29 AC 531 ms
25,836 KB
testcase_30 AC 2,374 ms
28,016 KB
testcase_31 AC 3,207 ms
26,028 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 1");
            //1
            //赤い石が2個、緑の石が1個、青の石が1個ある。
            //それぞれ1個の石を使って1つのアクセサリーができる。
            //赤い石が1つ残るがもうアクセサリーは作れない。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("1 0 3");
            //1
            //赤い石が1個、緑の石が0個、青の石が3個ある。
            //緑の石が無いが青い石2個を緑の石1個に変えることができる。
            //よって、赤、緑、青の石を1個ずつでアクセサリーが1つできる。
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("2 2 0");
            //0
            //赤い石が2個、緑の石が2個、青の石が0個ある。
            //この場合、どのようにしてもアクセサリーはできない。
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("5 18 36");
            //16
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] ColorArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        int TotalCreateCnt = 0;

        //石を1つずつ使って、アクセサリを作れるだけ作る
        Action CreateAct = () =>
        {
            int MinCnt = ColorArr.Min();
            if (MinCnt == 0) return;
            TotalCreateCnt += MinCnt;
            for (int I = 0; I <= ColorArr.GetUpperBound(0); I++)
                ColorArr[I] -= MinCnt;
            //PrintInfo(ColorArr);
        };

        //最大数の石を、最小数の石に交換
        Action ChangeAct = () =>
        {
            int MinCnt = ColorArr[0], MaxCnt = ColorArr[0];
            int wkIndMin = 0, wkIndMax = 0;

            for (int I = 1; I <= ColorArr.GetUpperBound(0); I++) {
                if (MinCnt > ColorArr[I]) {
                    MinCnt = ColorArr[I];
                    wkIndMin = I;
                }
                if (MaxCnt < ColorArr[I]) {
                    MaxCnt = ColorArr[I];
                    wkIndMax = I;
                }

            }
            ColorArr[wkIndMax] -= 2;
            ColorArr[wkIndMin]++;
            //PrintInfo(ColorArr);
        };

        CreateAct();

        while (Array.Exists(ColorArr, X => X >= 2)) {
            ChangeAct();
            CreateAct();
        }
        Console.WriteLine(TotalCreateCnt);
    }

    //石情報をデバッグ表示
    static void PrintInfo(int[] pColorArr)
    {
        Array.ForEach(pColorArr, X => Console.Write("{0},", X));
        Console.WriteLine();
    }
}
0