結果

問題 No.29 パワーアップ
ユーザー YOSHIYOSHI
提出日時 2021-02-17 23:37:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 888 bytes
コンパイル時間 3,708 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 56,412 KB
最終ジャッジ日時 2023-10-12 09:24:37
合計ジャッジ時間 7,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,956 KB
testcase_01 AC 123 ms
56,112 KB
testcase_02 AC 122 ms
56,056 KB
testcase_03 AC 127 ms
55,632 KB
testcase_04 AC 124 ms
56,228 KB
testcase_05 AC 133 ms
55,772 KB
testcase_06 AC 133 ms
55,636 KB
testcase_07 AC 129 ms
56,076 KB
testcase_08 AC 124 ms
55,904 KB
testcase_09 AC 124 ms
56,404 KB
testcase_10 AC 133 ms
56,040 KB
testcase_11 AC 134 ms
55,932 KB
testcase_12 AC 127 ms
55,772 KB
testcase_13 AC 127 ms
55,820 KB
testcase_14 AC 131 ms
55,876 KB
testcase_15 AC 129 ms
56,324 KB
testcase_16 AC 132 ms
56,012 KB
testcase_17 AC 124 ms
55,588 KB
testcase_18 AC 130 ms
55,480 KB
testcase_19 AC 130 ms
56,236 KB
testcase_20 AC 122 ms
56,100 KB
testcase_21 AC 124 ms
56,412 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