結果

問題 No.11 カードマッチ
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-07-19 16:33:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,180 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 63,240 KB
実行使用メモリ 6,040 KB
最終ジャッジ日時 2023-08-05 20:15:35
合計ジャッジ時間 1,442 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 4 ms
5,988 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
5,952 KB
testcase_09 AC 5 ms
6,040 KB
testcase_10 AC 4 ms
5,808 KB
testcase_11 AC 4 ms
5,924 KB
testcase_12 AC 4 ms
5,868 KB
testcase_13 AC 4 ms
5,880 KB
testcase_14 AC 4 ms
6,008 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,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]);
	}
	// cout << "ans" << ans << endl;

	// 数字が同じでマークが異なるものを求める
	//使用されているマークを調べる
	rep(i, n) mark[sk[i].first] = true;
	int cnt_mark = w;
	rep(i, w){
		if(mark[i]) cnt_mark--; 
	}
	// cout << "cnt_mark" << cnt_mark << endl;
	//使用されている数字を調べる
	rep(i, n) num[sk[i].second] = true;
	int cnt_num = 0;
	rep(i, h){
		if(num[i]) cnt_num++;
	}
	// cout << "cnt_num" << cnt_num << endl;
	ans += cnt_mark * cnt_num;
	cout << ans << endl;
	return 0;
}
0