結果

問題 No.11 カードマッチ
ユーザー YamaKasa
提出日時 2018-06-10 02:28:57
言語 Java
(openjdk 23)
結果
AC  
実行時間 224 ms / 5,000 ms
コード長 1,031 bytes
コンパイル時間 2,974 ms
コンパイル使用メモリ 79,196 KB
実行使用メモリ 61,204 KB
最終ジャッジ日時 2024-06-30 13:09:21
合計ジャッジ時間 6,564 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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