結果

問題 No.11 カードマッチ
ユーザー YamaKasaYamaKasa
提出日時 2018-06-10 02:28:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 210 ms / 5,000 ms
コード長 1,031 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 76,056 KB
実行使用メモリ 62,908 KB
最終ジャッジ日時 2023-09-13 02:31:33
合計ジャッジ時間 6,281 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
57,920 KB
testcase_01 AC 122 ms
54,408 KB
testcase_02 AC 121 ms
56,248 KB
testcase_03 AC 122 ms
55,828 KB
testcase_04 AC 186 ms
58,680 KB
testcase_05 AC 126 ms
55,916 KB
testcase_06 AC 207 ms
62,908 KB
testcase_07 AC 173 ms
58,744 KB
testcase_08 AC 192 ms
58,520 KB
testcase_09 AC 210 ms
62,832 KB
testcase_10 AC 194 ms
58,016 KB
testcase_11 AC 194 ms
58,512 KB
testcase_12 AC 196 ms
58,484 KB
testcase_13 AC 191 ms
62,324 KB
testcase_14 AC 192 ms
58,868 KB
testcase_15 AC 147 ms
56,016 KB
testcase_16 AC 160 ms
56,364 KB
testcase_17 AC 148 ms
56,064 KB
testcase_18 AC 151 ms
56,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int N = scan.nextInt();

		long ans = 0;
		int []a = new int[H + 1];
		Arrays.fill(a, 0);
		// 隣接リスト
		Map<Integer, ArrayList<Integer>> map =
				new TreeMap<Integer, ArrayList<Integer>>();
		for(int i = 0; i < N; i++) {
			int S = scan.nextInt();
			int K = scan.nextInt();
			a[K] = 1;
			if(!map.containsKey(S)) {
				ArrayList<Integer> list = new ArrayList<Integer>();
				list.add(K);
				map.put(S, list);
			}else {
				map.get(S).add(K);
			}
		}
		scan.close();
		int cnt = 0;
		for(int i = 1 ; i <= H; i++) {
			if(a[i] == 1) {
				cnt ++;
			}
		}
		for(int i = 1; i <= W; i++) {
			if(map.containsKey(i)) {
				ans += (long) (H - map.get(i).size());
			}else {
				ans += (long) cnt;
			}
		}
		System.out.println(ans);
	}
}
0