結果

問題 No.161 制限ジャンケン
ユーザー GrenacheGrenache
提出日時 2016-02-14 17:20:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 1,181 bytes
コンパイル時間 3,651 ms
コンパイル使用メモリ 74,832 KB
実行使用メモリ 56,420 KB
最終ジャッジ日時 2023-08-20 04:45:41
合計ジャッジ時間 6,910 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,944 KB
testcase_01 AC 123 ms
55,716 KB
testcase_02 AC 122 ms
55,668 KB
testcase_03 AC 126 ms
56,016 KB
testcase_04 AC 125 ms
55,764 KB
testcase_05 AC 124 ms
55,740 KB
testcase_06 AC 128 ms
55,992 KB
testcase_07 AC 125 ms
55,668 KB
testcase_08 AC 128 ms
55,740 KB
testcase_09 AC 124 ms
55,524 KB
testcase_10 AC 124 ms
55,852 KB
testcase_11 AC 124 ms
56,076 KB
testcase_12 AC 124 ms
56,252 KB
testcase_13 AC 128 ms
53,992 KB
testcase_14 AC 125 ms
56,420 KB
testcase_15 AC 124 ms
56,404 KB
testcase_16 AC 123 ms
55,820 KB
testcase_17 AC 123 ms
56,016 KB
testcase_18 AC 125 ms
55,940 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