結果

問題 No.161 制限ジャンケン
ユーザー GrenacheGrenache
提出日時 2016-02-14 17:20:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 1,181 bytes
コンパイル時間 3,333 ms
コンパイル使用メモリ 77,572 KB
実行使用メモリ 54,308 KB
最終ジャッジ日時 2024-05-07 12:11:44
合計ジャッジ時間 5,976 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
54,100 KB
testcase_01 AC 113 ms
53,580 KB
testcase_02 AC 113 ms
53,464 KB
testcase_03 AC 120 ms
54,308 KB
testcase_04 AC 116 ms
53,992 KB
testcase_05 AC 105 ms
52,924 KB
testcase_06 AC 113 ms
53,216 KB
testcase_07 AC 117 ms
53,996 KB
testcase_08 AC 116 ms
52,976 KB
testcase_09 AC 114 ms
52,844 KB
testcase_10 AC 120 ms
54,016 KB
testcase_11 AC 105 ms
52,948 KB
testcase_12 AC 116 ms
52,808 KB
testcase_13 AC 109 ms
53,508 KB
testcase_14 AC 116 ms
53,244 KB
testcase_15 AC 118 ms
54,000 KB
testcase_16 AC 124 ms
53,936 KB
testcase_17 AC 117 ms
54,272 KB
testcase_18 AC 115 ms
53,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder161 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int g = sc.nextInt();
        int c = sc.nextInt();
        int p = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int og = 0;
        int oc = 0;
        int op = 0;
        for (char ch : s) {
        	if (ch == 'G') {
        		og++;
        	} else if (ch == 'C') {
        		oc++;
        	} else if (ch == 'P') {
        		op++;
        	}
        }

        int ret = 0;
        int tmp;

        tmp = Math.min(g, oc);
        g -= tmp;
        oc -= tmp;
        ret += 3 * tmp;
        tmp = Math.min(c, op);
        c -= tmp;
        op -= tmp;
        ret += 3 * tmp;
        tmp = Math.min(p, og);
        p -= tmp;
        og -= tmp;
        ret += 3 * tmp;

        tmp = Math.min(g, og);
        g -= tmp;
        og -= tmp;
        ret += tmp;
        tmp = Math.min(c, oc);
        c -= tmp;
        oc -= tmp;
        ret += tmp;
        tmp = Math.min(p, op);
        p -= tmp;
        op -= tmp;
        ret += tmp;

        System.out.println(ret);

        sc.close();
    }
}
0