結果

問題 No.11 カードマッチ
ユーザー scache
提出日時 2014-11-12 03:32:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 77,252 KB
実行使用メモリ 43,604 KB
最終ジャッジ日時 2024-10-11 19:11:57
合計ジャッジ時間 5,820 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		int[] s = new int[n];
		int[] k = new int[n];
		for(int i=0;i<n;i++){
			s[i] = sc.nextInt();
			k[i] = sc.nextInt();
		}
		solve(w, h, s, k);
	}

	public void solve(int W, int H, int[] s, int[] k) {
		boolean[] mark = new boolean[W+1];
		boolean[] number = new boolean[H+1];
		
		for(int i=0;i<s.length;i++){
			mark[s[i]] = true;
			number[k[i]] = true;
		}
		
		long markNum = 0;
		for(int i=0;i<mark.length;i++){
			if(mark[i])
				markNum++;
		}
		long numNum = 0;
		for(int i=0;i<number.length;i++){
			if(number[i])
				numNum++;
		}

		long res = markNum*H+numNum*W-markNum*numNum-s.length;
		
		System.out.println(res);
		
	}

}
0