結果

問題 No.11 カードマッチ
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-07-20 01:21:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,063 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 62,048 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 16:57:04
合計ジャッジ時間 1,055 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

const int MAX_W = 1000010, MAX_H = 1000010;
int cnt[MAX_W] = {0};
bool mark[MAX_W] = {false};
bool num[MAX_H] = {false};

int main(void){
	int w, h, n, ans = 0;
	cin >> w >> h >> n;
	vector<pair<int, int> > sk(n);
	rep(i, n){
		int s, k;
		cin >> s >> k; s--; k--;
		sk[i].first = s; sk[i].second = k;
	}

	//マークが同じで数字が異なるものを求める
	//一つのマークごとにいくつの数字があるかをメモっておく
	rep(i, n)cnt[sk[i].first]++;
	rep(i, w){
		if(cnt[i] != 0) ans += (h - cnt[i]);
	}

	// 数字が同じでマークが異なるものを求める
	//使用されているマークを調べる
	rep(i, n) mark[sk[i].first] = true;
	int cnt_mark = w;
	rep(i, w){
		if(mark[i]) cnt_mark--; 
	}

	//使用されている数字を調べる
	rep(i, n) num[sk[i].second] = true;
	int cnt_num = 0;
	rep(i, h){
		if(num[i]) cnt_num++;
	}
	ans += cnt_mark * cnt_num;
	
	cout << ans << endl;
	return 0;
}
0