結果

問題 No.29 パワーアップ
ユーザー l1267976l1267976
提出日時 2017-03-08 18:41:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 1,411 bytes
コンパイル時間 3,909 ms
コンパイル使用メモリ 73,872 KB
実行使用メモリ 56,412 KB
最終ジャッジ日時 2023-09-06 00:14:47
合計ジャッジ時間 7,895 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
56,072 KB
testcase_01 AC 126 ms
55,944 KB
testcase_02 AC 125 ms
55,780 KB
testcase_03 AC 128 ms
55,736 KB
testcase_04 AC 125 ms
56,412 KB
testcase_05 AC 141 ms
56,204 KB
testcase_06 AC 139 ms
55,796 KB
testcase_07 AC 132 ms
55,624 KB
testcase_08 AC 134 ms
55,768 KB
testcase_09 AC 125 ms
55,832 KB
testcase_10 AC 142 ms
56,068 KB
testcase_11 AC 143 ms
56,404 KB
testcase_12 AC 126 ms
56,004 KB
testcase_13 AC 139 ms
55,976 KB
testcase_14 AC 138 ms
55,664 KB
testcase_15 AC 138 ms
55,892 KB
testcase_16 AC 139 ms
53,992 KB
testcase_17 AC 127 ms
55,968 KB
testcase_18 AC 131 ms
56,360 KB
testcase_19 AC 132 ms
55,488 KB
testcase_20 AC 122 ms
55,600 KB
testcase_21 AC 123 ms
55,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No29 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] items = new int[10];

        for (int i = 0; i < n; i++) {
            int[] gets = new int[3];
            for (int j = 0; j < gets.length; j++) {
                gets[j] = sc.nextInt() - 1;
            }

            for (int j = 0; j < gets.length; j++) {
                items[gets[j]]++;
            }
        }

        int powerUpCnt = 0;

        for (int i = 0; i < items.length; i++) {
            powerUpCnt += items[i] / 2;
            items[i] = items[i] % 2;
        }

        while (canPowerUp(items)) {
            int cnt = 0;

            for (int i = 0; i < items.length; i++) {
                if (items[i] > 0) {
                    cnt++;
                    items[i]--;

                    if (cnt >= 4) {
                        powerUpCnt++;
                        break;
                    }
                }
            }
        }

        System.out.println(powerUpCnt);

        sc.locale();
    }

    private static boolean canPowerUp(int[] items) {
        int cnt = 0;

        for (int val : items) {
            if (val > 0) {
                cnt++;
            }
        }

        if (cnt >= 4) {
            return true;
        } else {
            return false;
        }
    }

}
0