結果

問題 No.11 カードマッチ
ユーザー shinwisteriashinwisteria
提出日時 2017-03-31 21:04:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 886 bytes
コンパイル時間 3,222 ms
コンパイル使用メモリ 80,084 KB
実行使用メモリ 57,604 KB
最終ジャッジ日時 2023-09-21 10:45:38
合計ジャッジ時間 6,657 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,764 KB
testcase_01 AC 118 ms
56,108 KB
testcase_02 AC 118 ms
57,604 KB
testcase_03 AC 117 ms
56,248 KB
testcase_04 AC 132 ms
55,976 KB
testcase_05 AC 117 ms
55,964 KB
testcase_06 AC 130 ms
55,968 KB
testcase_07 AC 141 ms
56,360 KB
testcase_08 AC 129 ms
55,852 KB
testcase_09 AC 136 ms
55,948 KB
testcase_10 AC 127 ms
55,768 KB
testcase_11 AC 130 ms
55,676 KB
testcase_12 AC 130 ms
55,876 KB
testcase_13 AC 132 ms
56,180 KB
testcase_14 AC 133 ms
56,028 KB
testcase_15 AC 135 ms
56,732 KB
testcase_16 AC 137 ms
55,640 KB
testcase_17 AC 134 ms
56,228 KB
testcase_18 AC 134 ms
55,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.TreeSet;
public class Cardmatch {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int W = s.nextInt(),H = s.nextInt(),N = s.nextInt();
		int[] S = new int[N];
		int[] K = new int[N];
		TreeSet<Integer> Mark = new TreeSet<>();
		TreeSet<Integer> Number = new TreeSet<>();
		for(int i = 0;i < N ;i++){
			S[i] = s.nextInt();
			K[i] = s.nextInt();
		}
		s.close();
		long count = 0;
		for(int i = 0;i < N;i++){
			if(Mark.contains(S[i]) && Number.contains(K[i])){
				count--;
			}else if(Mark.contains(S[i])){
				count += (W - Mark.size()-1);
				Number.add(K[i]);
			}else if(Number.contains(K[i])){
				count += (H - Number.size()-1);
				Mark.add(S[i]);
			}else{
				count += (W-Mark.size() + H-Number.size() -2);
				Mark.add(S[i]);
				Number.add(K[i]);
			}
		}
		System.out.println(count);
		

	}

}
0