結果

問題 No.29 パワーアップ
ユーザー YOSHIYOSHI
提出日時 2021-02-17 23:37:25
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 95 ms / 5,000 ms
コード長 888 bytes
コンパイル時間 2,618 ms
使用メモリ 38,264 KB
最終ジャッジ日時 2023-02-26 18:50:37
合計ジャッジ時間 5,743 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 81 ms
37,892 KB
testcase_01 AC 80 ms
38,060 KB
testcase_02 AC 78 ms
38,000 KB
testcase_03 AC 85 ms
38,052 KB
testcase_04 AC 81 ms
37,820 KB
testcase_05 AC 85 ms
38,056 KB
testcase_06 AC 85 ms
38,196 KB
testcase_07 AC 82 ms
38,056 KB
testcase_08 AC 82 ms
38,188 KB
testcase_09 AC 82 ms
38,228 KB
testcase_10 AC 95 ms
38,172 KB
testcase_11 AC 94 ms
38,132 KB
testcase_12 AC 82 ms
37,980 KB
testcase_13 AC 85 ms
37,924 KB
testcase_14 AC 87 ms
38,264 KB
testcase_15 AC 84 ms
38,196 KB
testcase_16 AC 92 ms
38,188 KB
testcase_17 AC 90 ms
37,996 KB
testcase_18 AC 93 ms
38,248 KB
testcase_19 AC 94 ms
38,080 KB
testcase_20 AC 83 ms
37,884 KB
testcase_21 AC 82 ms
38,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.stream.Stream;

public class No00000029_Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		Map<Integer, Integer> cntMap = new HashMap<Integer, Integer>();


		int n = Integer.parseInt(scan.nextLine());
		for(int i = 0; i < n; i++) {
			int[] arr = Stream.of(scan.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
			for(int num : arr) {
				if(cntMap.containsKey(num)) {
					cntMap.put(num, cntMap.get(num) + 1);
				} else {
					cntMap.put(num, 1);
				}
			}
		}

		int sameCnt = 0;
		int anyCnt = 0;
		for(Entry<Integer, Integer> entry : cntMap.entrySet()) {
			int cnt = entry.getValue();
			sameCnt += cnt / 2;
			anyCnt += cnt % 2;
		}

		System.out.println(sameCnt + anyCnt / 4);

		scan.close();

	}

}
0