結果

問題 No.29 パワーアップ
ユーザー kitamoto0407kitamoto0407
提出日時 2024-03-16 18:10:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 85 ms / 5,000 ms
コード長 2,051 bytes
コンパイル時間 3,705 ms
コンパイル使用メモリ 79,772 KB
実行使用メモリ 55,016 KB
最終ジャッジ日時 2024-03-16 18:10:48
合計ジャッジ時間 5,683 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
52,952 KB
testcase_01 AC 71 ms
52,924 KB
testcase_02 AC 72 ms
54,776 KB
testcase_03 AC 73 ms
54,844 KB
testcase_04 AC 73 ms
54,988 KB
testcase_05 AC 83 ms
54,896 KB
testcase_06 AC 81 ms
54,896 KB
testcase_07 AC 74 ms
55,008 KB
testcase_08 AC 75 ms
52,992 KB
testcase_09 AC 72 ms
54,884 KB
testcase_10 AC 85 ms
55,008 KB
testcase_11 AC 82 ms
55,016 KB
testcase_12 AC 70 ms
54,768 KB
testcase_13 AC 75 ms
54,904 KB
testcase_14 AC 80 ms
54,880 KB
testcase_15 AC 79 ms
54,884 KB
testcase_16 AC 79 ms
55,004 KB
testcase_17 AC 74 ms
54,908 KB
testcase_18 AC 74 ms
54,864 KB
testcase_19 AC 76 ms
55,008 KB
testcase_20 AC 72 ms
54,764 KB
testcase_21 AC 72 ms
54,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

// 処理
class Process {
    private PrintWriter printWriter;
    private int[] a;
    private int[] b;
    private int[] c;

    Process(PrintWriter printWriter, int[] a, int[] b, int[] c) {
        this.printWriter = printWriter;
        this.a = a;
        this.b = b;
        this.c = c;
    }

    // 結果を出力
    void printResult() throws IOException {
        var itemCounts = new int[10];
        for(int i = 0; i < a.length; i++) {
            itemCounts[a[i] - 1]++;
            itemCounts[b[i] - 1]++;
            itemCounts[c[i] - 1]++;
        }

        var powerUpCount = 0;
        for(int i = 0; i < itemCounts.length; i++) {
            powerUpCount  += itemCounts[i] / 2;
            itemCounts[i] -= 2 * (itemCounts[i] / 2);
        }

        int sumOfItems = IntStream.of(itemCounts).sum();

        powerUpCount += sumOfItems / 4;

        printWriter.println(powerUpCount);
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        var bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        var printWriter    = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        // 入力
        int N = Integer.parseInt(bufferedReader.readLine().trim());

        var a = new int[N];
        var b = new int[N];
        var c = new int[N];
        
        var input = new int[3];
        for(int n = 0; n < N; n++) {
            input = Stream.of(bufferedReader.readLine().trim().split("[ ]+")).mapToInt(Integer::parseInt).toArray();
            a[n] = input[0];
            b[n] = input[1];
            c[n] = input[2];
        }

        // Process クラスで処理を行う
        var process = new Process(printWriter, a, b, c);
        process.printResult();

        // 各ストリームを閉じる
        // 出力ストリームを閉じるときに標準出力に文字を出力する
        bufferedReader.close();
        printWriter.close();
    }
}
0