結果
問題 | No.161 制限ジャンケン |
ユーザー |
|
提出日時 | 2020-03-09 00:29:00 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 137 ms / 5,000 ms |
コード長 | 1,087 bytes |
コンパイル時間 | 3,578 ms |
コンパイル使用メモリ | 77,420 KB |
実行使用メモリ | 41,464 KB |
最終ジャッジ日時 | 2024-11-07 20:20:02 |
合計ジャッジ時間 | 6,972 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
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"; } } } }