結果

問題 No.161 制限ジャンケン
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-28 21:52:26
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 2,340 bytes
コンパイル時間 2,433 ms
コンパイル使用メモリ 106,252 KB
実行使用メモリ 23,928 KB
最終ジャッジ日時 2023-08-20 04:39:04
合計ジャッジ時間 4,675 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,836 KB
testcase_01 AC 63 ms
23,892 KB
testcase_02 AC 62 ms
21,788 KB
testcase_03 AC 64 ms
23,928 KB
testcase_04 AC 63 ms
21,896 KB
testcase_05 AC 63 ms
21,820 KB
testcase_06 AC 63 ms
19,948 KB
testcase_07 AC 63 ms
21,924 KB
testcase_08 AC 64 ms
23,880 KB
testcase_09 AC 63 ms
21,868 KB
testcase_10 AC 64 ms
23,820 KB
testcase_11 AC 63 ms
23,872 KB
testcase_12 AC 62 ms
21,808 KB
testcase_13 AC 63 ms
21,852 KB
testcase_14 AC 63 ms
23,880 KB
testcase_15 AC 62 ms
23,928 KB
testcase_16 AC 62 ms
19,736 KB
testcase_17 AC 63 ms
21,876 KB
testcase_18 AC 63 ms
22,016 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");
            WillReturn.Add("CCGP");
            //12
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("0 0 5");
            WillReturn.Add("CCCCC");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("7 6 5");
            WillReturn.Add("GCPGPCPGGGPCCCGPGP");
            //50
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int CardCntG = wkArr[0];
        int CardCntC = wkArr[1];
        int CardCntP = wkArr[2];

        char[] SArr = InputList[1].ToCharArray();
        int AiteCntG = SArr.Count(X => X == 'G');
        int AiteCntC = SArr.Count(X => X == 'C');
        int AiteCntP = SArr.Count(X => X == 'P');

        int Score = 0;

        //勝てるカードを全て割当
        Score += ExecWariate(ref CardCntG, ref AiteCntC) * 3;
        Score += ExecWariate(ref CardCntC, ref AiteCntP) * 3;
        Score += ExecWariate(ref CardCntP, ref AiteCntG) * 3;

        //あいこになるカードを全て割当
        Score += ExecWariate(ref CardCntG, ref AiteCntG);
        Score += ExecWariate(ref CardCntC, ref AiteCntC);
        Score += ExecWariate(ref CardCntP, ref AiteCntP);

        Console.WriteLine(Score);
    }

    //貪欲法で、カードを割当し、割当枚数を返す
    static int ExecWariate(ref int pCardCnt, ref int pAiteCnt)
    {
        int WillReturn;
        //全て割当可能の場合
        if (pCardCnt <= pAiteCnt) {
            WillReturn = pCardCnt;
            pAiteCnt -= pCardCnt;
            pCardCnt = 0;
            return WillReturn;
        }
        //一部割当可能の場合
        WillReturn = pAiteCnt;
        pCardCnt -= pAiteCnt;
        pAiteCnt = 0;
        return WillReturn;
    }
}
0