結果
| 問題 | 
                            No.91 赤、緑、青の石
                             | 
                    
| コンテスト | |
| ユーザー | 
                             明智重蔵
                         | 
                    
| 提出日時 | 2015-09-18 05:09:25 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3,509 ms / 5,000 ms | 
| コード長 | 3,148 bytes | 
| コンパイル時間 | 1,001 ms | 
| コンパイル使用メモリ | 116,416 KB | 
| 実行使用メモリ | 31,676 KB | 
| 最終ジャッジ日時 | 2024-06-24 06:51:53 | 
| 合計ジャッジ時間 | 37,200 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 28 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
    }
}
            
            
            
        
            
明智重蔵