結果

問題 No.11 カードマッチ
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-07-19 16:33:28
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,180 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 62,992 KB
実行使用メモリ 7,756 KB
最終ジャッジ日時 2024-10-15 17:20:17
合計ジャッジ時間 1,453 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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