結果

問題 No.29 パワーアップ
コンテスト
ユーザー yuppe19 😺
提出日時 2015-04-22 14:18:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 1,401 bytes
コンパイル時間 2,625 ms
コンパイル使用メモリ 91,900 KB
実行使用メモリ 46,948 KB
最終ジャッジ日時 2025-10-24 20:52:36
合計ジャッジ時間 6,618 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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