結果

問題 No.11 カードマッチ
ユーザー scachescache
提出日時 2014-11-12 03:32:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 76,984 KB
実行使用メモリ 43,636 KB
最終ジャッジ日時 2024-04-20 00:13:29
合計ジャッジ時間 4,768 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
40,924 KB
testcase_01 AC 107 ms
40,784 KB
testcase_02 AC 103 ms
40,548 KB
testcase_03 AC 105 ms
40,840 KB
testcase_04 AC 123 ms
42,028 KB
testcase_05 AC 103 ms
41,336 KB
testcase_06 AC 137 ms
43,636 KB
testcase_07 AC 124 ms
42,044 KB
testcase_08 AC 128 ms
42,300 KB
testcase_09 AC 128 ms
43,468 KB
testcase_10 AC 124 ms
43,068 KB
testcase_11 AC 134 ms
42,640 KB
testcase_12 AC 124 ms
42,964 KB
testcase_13 AC 130 ms
42,712 KB
testcase_14 AC 130 ms
41,796 KB
testcase_15 AC 116 ms
41,128 KB
testcase_16 AC 127 ms
41,180 KB
testcase_17 AC 120 ms
40,784 KB
testcase_18 AC 127 ms
41,532 KB
権限があれば一括ダウンロードができます

ソースコード

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