結果

問題 No.161 制限ジャンケン
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-31 14:29:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 865 bytes
コンパイル時間 2,690 ms
コンパイル使用メモリ 77,200 KB
実行使用メモリ 41,572 KB
最終ジャッジ日時 2024-04-30 01:32:37
合計ジャッジ時間 6,712 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,184 KB
testcase_01 AC 119 ms
40,124 KB
testcase_02 AC 130 ms
41,308 KB
testcase_03 AC 131 ms
41,240 KB
testcase_04 AC 134 ms
41,052 KB
testcase_05 AC 132 ms
41,380 KB
testcase_06 AC 137 ms
41,372 KB
testcase_07 AC 132 ms
41,572 KB
testcase_08 AC 134 ms
41,020 KB
testcase_09 AC 132 ms
41,368 KB
testcase_10 AC 131 ms
41,196 KB
testcase_11 AC 135 ms
41,276 KB
testcase_12 AC 133 ms
41,164 KB
testcase_13 AC 138 ms
41,020 KB
testcase_14 AC 134 ms
41,180 KB
testcase_15 AC 136 ms
41,272 KB
testcase_16 AC 133 ms
41,396 KB
testcase_17 AC 133 ms
41,184 KB
testcase_18 AC 120 ms
40,264 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