結果

問題 No.29 パワーアップ
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-04-22 14:18:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 1,401 bytes
コンパイル時間 2,544 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 56,592 KB
最終ジャッジ日時 2023-09-18 08:13:49
合計ジャッジ時間 6,866 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
55,904 KB
testcase_01 AC 135 ms
55,760 KB
testcase_02 AC 137 ms
56,360 KB
testcase_03 AC 136 ms
56,008 KB
testcase_04 AC 135 ms
55,948 KB
testcase_05 AC 146 ms
54,512 KB
testcase_06 AC 143 ms
56,540 KB
testcase_07 AC 140 ms
56,304 KB
testcase_08 AC 139 ms
55,832 KB
testcase_09 AC 138 ms
56,164 KB
testcase_10 AC 146 ms
56,076 KB
testcase_11 AC 150 ms
56,224 KB
testcase_12 AC 137 ms
55,980 KB
testcase_13 AC 142 ms
55,880 KB
testcase_14 AC 148 ms
55,956 KB
testcase_15 AC 145 ms
55,940 KB
testcase_16 AC 146 ms
56,592 KB
testcase_17 AC 138 ms
55,892 KB
testcase_18 AC 140 ms
56,248 KB
testcase_19 AC 141 ms
56,324 KB
testcase_20 AC 138 ms
55,608 KB
testcase_21 AC 137 ms
56,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import static java.lang.Math.*;

// (ΦωΦ)<何事もやりすぎはよくない
public class Main {
    private void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        List<List<Integer>> lines = IntStream.range(0, n)
                                             .mapToObj(i -> Stream.of(sc.nextLine().split(" "))
                                                             .map(Integer::valueOf)
                                                             .collect(Collectors.toList()))
                                             .collect(Collectors.toList());
        List<Integer> flattened = lines.stream().flatMap(List::stream).collect(Collectors.toList());
        Set<Integer> sett = new HashSet<>(flattened);
        List<Integer> values = sett.stream()
                                   .map(e -> Collections.frequency(flattened, e))
                                   .collect(Collectors.toList());
        long res = values.stream()
                         .map(e -> e/2)
                         .reduce(0, (x, y) -> x + y) +
                   values.stream()
                         .filter(e -> e%2==1)
                         .count() / 4;
        System.out.println(res);
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}
0