結果

問題 No.29 パワーアップ
ユーザー yuppe19 😺
提出日時 2015-04-22 14:18:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 1,401 bytes
コンパイル時間 2,714 ms
コンパイル使用メモリ 91,472 KB
実行使用メモリ 41,856 KB
最終ジャッジ日時 2024-07-05 00:13:34
合計ジャッジ時間 7,189 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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