結果

問題 No.161 制限ジャンケン
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-31 14:29:49
言語 Java19
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 865 bytes
コンパイル時間 2,426 ms
コンパイル使用メモリ 74,156 KB
実行使用メモリ 55,884 KB
最終ジャッジ日時 2023-08-12 11:32:21
合計ジャッジ時間 6,737 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
55,540 KB
testcase_01 AC 128 ms
55,632 KB
testcase_02 AC 132 ms
55,624 KB
testcase_03 AC 134 ms
55,536 KB
testcase_04 AC 130 ms
55,576 KB
testcase_05 AC 130 ms
55,580 KB
testcase_06 AC 132 ms
55,636 KB
testcase_07 AC 129 ms
55,412 KB
testcase_08 AC 133 ms
55,864 KB
testcase_09 AC 125 ms
55,536 KB
testcase_10 AC 126 ms
55,748 KB
testcase_11 AC 124 ms
55,884 KB
testcase_12 AC 126 ms
55,536 KB
testcase_13 AC 126 ms
55,632 KB
testcase_14 AC 131 ms
55,332 KB
testcase_15 AC 130 ms
55,716 KB
testcase_16 AC 125 ms
55,580 KB
testcase_17 AC 123 ms
55,348 KB
testcase_18 AC 122 ms
55,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int g=scanner.nextInt();
		int c=scanner.nextInt();
		int p=scanner.nextInt();
		String s=scanner.next();
		int I[]= {g,c,p};
		int Y[]=new int[3];
		int sc=0;
		for(int i=0;i<s.length();i++) {
			char y=s.charAt(i);
			if(y=='G')Y[0]++;
			else if(y=='C')Y[1]++;
			else Y[2]++;
		}
		for(int i=0;i<3;i++) {
			int yi=i+1;
			if(yi==3)yi=0;
			if(I[i]<=Y[yi]) {
				sc+=I[i]*3;
				Y[yi]-=I[i];
				I[i]=0;
			}
			else {
				sc+=Y[yi]*3;
				I[i]-=Y[yi];
				Y[yi]=0;
			}
		}
		for(int i=0;i<3;i++) {
			int yi=i;
			if(yi==3)yi=0;
			if(I[i]<=Y[yi]) {
				sc+=I[i];
				Y[yi]-=I[i];
				I[i]=0;
			}
			else {
				sc+=Y[yi];
				I[i]-=Y[yi];
				Y[yi]=0;
			}
		}
		System.out.println(sc);
	}
}
0