結果

問題 No.161 制限ジャンケン
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-28 21:43:01
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,375 bytes
コンパイル時間 2,526 ms
コンパイル使用メモリ 104,556 KB
実行使用メモリ 23,988 KB
最終ジャッジ日時 2023-09-25 19:08:27
合計ジャッジ時間 4,936 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 64 ms
21,896 KB
testcase_02 AC 62 ms
19,892 KB
testcase_03 AC 63 ms
22,020 KB
testcase_04 WA -
testcase_05 AC 63 ms
23,836 KB
testcase_06 AC 65 ms
21,804 KB
testcase_07 AC 64 ms
21,724 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 64 ms
21,920 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 64 ms
23,860 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 65 ms
19,892 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 = "Input4";

    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;
    }

    //No.161 制限ジャンケン
    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;
            pCardCnt = 0;
            pAiteCnt -= pCardCnt;
            return WillReturn;
        }
        //一部割当可能の場合
        WillReturn = pAiteCnt;
        pCardCnt -= pAiteCnt;
        pAiteCnt = 0;
        return WillReturn;
    }
}
0