結果

問題 No.161 制限ジャンケン
ユーザー htensaihtensai
提出日時 2019-12-30 10:07:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 1,472 bytes
コンパイル時間 2,643 ms
コンパイル使用メモリ 77,676 KB
実行使用メモリ 41,584 KB
最終ジャッジ日時 2024-04-25 08:57:11
合計ジャッジ時間 6,250 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
41,336 KB
testcase_01 AC 142 ms
41,312 KB
testcase_02 AC 137 ms
41,380 KB
testcase_03 AC 138 ms
41,384 KB
testcase_04 AC 136 ms
41,052 KB
testcase_05 AC 136 ms
41,164 KB
testcase_06 AC 127 ms
40,428 KB
testcase_07 AC 136 ms
41,524 KB
testcase_08 AC 143 ms
41,424 KB
testcase_09 AC 140 ms
41,264 KB
testcase_10 AC 138 ms
41,332 KB
testcase_11 AC 140 ms
41,384 KB
testcase_12 AC 139 ms
41,516 KB
testcase_13 AC 140 ms
41,048 KB
testcase_14 AC 139 ms
41,584 KB
testcase_15 AC 140 ms
41,464 KB
testcase_16 AC 138 ms
41,456 KB
testcase_17 AC 137 ms
41,464 KB
testcase_18 AC 140 ms
41,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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[] arr = sc.next().toCharArray();
        int gCount = 0;
        int cCount = 0;
        int pCount = 0;
        for (char cc : arr) {
            switch (cc) {
                case 'G' :
                    gCount++;
                    break;
                case 'C' :
                    cCount++;
                    break;
                case 'P' :
                    pCount++;
                    break;
            }
        }
        int point = 0;
        if (gCount > p) {
            point += p * 3;
            gCount -= p;
            p = 0;
        } else {
            point += gCount * 3;
            p -= gCount;
            gCount = 0;
        }
        if (cCount > g) {
            point += g * 3;
            cCount -= g;
            g = 0;
        } else {
            point += cCount * 3;
            g -= cCount;
            cCount = 0;
        }
        if (pCount > c) {
            point += c * 3;
            pCount -= c;
            c = 0;
        } else {
            point += pCount * 3;
            c -= pCount;
            pCount = 0;
        }
        point += Math.min(gCount, g);
        point += Math.min(cCount, c);
        point += Math.min(pCount, p);
        System.out.println(point);
    }
}
0