結果

問題 No.161 制限ジャンケン
ユーザー tsunabittsunabit
提出日時 2020-03-09 00:29:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 1,087 bytes
コンパイル時間 3,222 ms
コンパイル使用メモリ 74,604 KB
実行使用メモリ 56,244 KB
最終ジャッジ日時 2023-08-07 16:03:06
合計ジャッジ時間 7,174 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,848 KB
testcase_01 AC 121 ms
56,088 KB
testcase_02 AC 122 ms
56,080 KB
testcase_03 AC 122 ms
55,884 KB
testcase_04 AC 121 ms
55,604 KB
testcase_05 AC 122 ms
55,756 KB
testcase_06 AC 125 ms
56,092 KB
testcase_07 AC 123 ms
55,936 KB
testcase_08 AC 124 ms
53,560 KB
testcase_09 AC 121 ms
55,476 KB
testcase_10 AC 125 ms
55,580 KB
testcase_11 AC 123 ms
56,244 KB
testcase_12 AC 123 ms
55,676 KB
testcase_13 AC 126 ms
55,952 KB
testcase_14 AC 124 ms
56,192 KB
testcase_15 AC 124 ms
55,828 KB
testcase_16 AC 124 ms
55,336 KB
testcase_17 AC 124 ms
55,608 KB
testcase_18 AC 123 ms
55,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No161 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] gcp = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
		String[] s = sc.next().split("");
		int ans = 0;
		
		ans += jan(gcp, 0, "C", s, 3);
		ans += jan(gcp, 1, "P", s, 3);
		ans += jan(gcp, 2, "G", s, 3);
		ans += jan(gcp, 0, "G", s, 1);
		ans += jan(gcp, 1, "C", s, 1);
		ans += jan(gcp, 2, "P", s, 1);
		System.out.println(ans);
		
	}
	public static int jan(int[] gcp, int y, String c, String[] s, int p) {
		int a = 0;
		int t = kaz(c, s);
		if(gcp[y] >= t) {
			gcp[y] -= t;
			a += t * p;
			del(c, s, t);
		}else {
			del(c, s, gcp[y]);
			a += gcp[y] * p;
			gcp[y] = 0;
		}
		return a;
	}
	
	public static int kaz(String c, String[] s) {
		int t = 0;
		for(int i = 0; i < s.length; i++) {
			if(c.equals(s[i])) t++;
		}
		return t;
	}
	public static void del(String c, String[] s, int k) {
		for(int i = 0; i < s.length; i++) {
			if(k == 0) return;
			if(c.equals(s[i])) {
				k--;
				s[i] = "Z";
			}
		}
	}
}
0