結果

問題 No.161 制限ジャンケン
ユーザー kenkooookenkoooo
提出日時 2015-03-06 00:10:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 940 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 78,484 KB
実行使用メモリ 56,016 KB
最終ジャッジ日時 2023-08-20 04:23:04
合計ジャッジ時間 5,429 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,648 KB
testcase_01 AC 125 ms
55,696 KB
testcase_02 AC 126 ms
56,016 KB
testcase_03 AC 124 ms
55,620 KB
testcase_04 AC 124 ms
55,228 KB
testcase_05 AC 123 ms
55,708 KB
testcase_06 AC 127 ms
55,848 KB
testcase_07 AC 126 ms
55,596 KB
testcase_08 AC 128 ms
55,508 KB
testcase_09 AC 124 ms
55,396 KB
testcase_10 AC 125 ms
55,492 KB
testcase_11 AC 125 ms
55,928 KB
testcase_12 AC 125 ms
55,860 KB
testcase_13 AC 127 ms
55,948 KB
testcase_14 AC 123 ms
55,840 KB
testcase_15 AC 126 ms
55,500 KB
testcase_16 AC 122 ms
55,996 KB
testcase_17 AC 124 ms
55,684 KB
testcase_18 AC 123 ms
55,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	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[] string = sc.next().toCharArray();
		Arrays.sort(string);
		sc.close();

		int oG = 0;
		int oC = 0;
		int oP = 0;
		for (char d : string) {
			if (d == 'G') {
				oG++;
			} else if (d == 'C') {
				oC++;
			} else {
				oP++;
			}
		}
		int point = 0;
		point += Math.min(G, oC) * 3;
		point += Math.min(C, oP) * 3;
		point += Math.min(P, oG) * 3;

		if (G >= oC) {
			G -= oC;
			oC = 0;
		} else {
			oC -= G;
			G = 0;
		}

		if (C >= oP) {
			C -= oP;
			oP = 0;
		} else {
			oP -= C;
			C = 0;
		}

		if (P >= oG) {
			P -= oG;
			oG = 0;
		} else {
			oG -= P;
			P = 0;
		}

		point += Math.min(G, oG);
		point += Math.min(C, oC);
		point += Math.min(P, oP);

		System.out.println(point);

	}

}
0