結果

問題 No.1605 Matrix Shape
ユーザー 沙耶花沙耶花
提出日時 2021-07-16 21:42:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 4,214 ms
コンパイル使用メモリ 264,688 KB
実行使用メモリ 5,720 KB
最終ジャッジ日時 2023-09-20 13:26:39
合計ジャッジ時間 7,804 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,452 KB
testcase_01 AC 4 ms
5,560 KB
testcase_02 AC 4 ms
5,412 KB
testcase_03 AC 4 ms
5,408 KB
testcase_04 AC 4 ms
5,572 KB
testcase_05 AC 4 ms
5,508 KB
testcase_06 AC 4 ms
5,476 KB
testcase_07 AC 4 ms
5,408 KB
testcase_08 AC 4 ms
5,568 KB
testcase_09 AC 4 ms
5,408 KB
testcase_10 AC 4 ms
5,572 KB
testcase_11 AC 3 ms
5,560 KB
testcase_12 AC 4 ms
5,412 KB
testcase_13 AC 4 ms
5,588 KB
testcase_14 AC 4 ms
5,452 KB
testcase_15 AC 4 ms
5,412 KB
testcase_16 AC 4 ms
5,408 KB
testcase_17 AC 4 ms
5,512 KB
testcase_18 AC 4 ms
5,408 KB
testcase_19 AC 128 ms
5,468 KB
testcase_20 AC 114 ms
5,412 KB
testcase_21 AC 114 ms
5,576 KB
testcase_22 AC 126 ms
5,420 KB
testcase_23 AC 125 ms
5,472 KB
testcase_24 AC 128 ms
5,492 KB
testcase_25 AC 77 ms
5,572 KB
testcase_26 AC 77 ms
5,496 KB
testcase_27 AC 79 ms
5,568 KB
testcase_28 AC 77 ms
5,460 KB
testcase_29 AC 77 ms
5,572 KB
testcase_30 AC 112 ms
5,532 KB
testcase_31 AC 113 ms
5,412 KB
testcase_32 AC 106 ms
5,720 KB
testcase_33 AC 106 ms
5,404 KB
testcase_34 AC 102 ms
5,712 KB
testcase_35 AC 98 ms
5,464 KB
testcase_36 AC 58 ms
5,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){
	
	int N;
	cin>>N;
	
	vector<int> da(200005,0),db(200005,0);
	
	dsu D(200005);
	
	rep(i,N){
		int h,w;
		cin>>h>>w;
		da[h]++;
		db[w]++;
		D.merge(h,w);
	}
	
	set<int> S;
	rep(i,da.size()){
		if(da[i]>0||db[i]>0){
			S.insert(D.leader(i));
		}
	}
	
	if(S.size()>1){
		cout<<0<<endl;
		return 0;
	}
	
	S.clear();
	set<int> S2;
	int cnt = 0;
	rep(i,da.size()){
		if(da[i]==0&&db[i]==0)continue;
		if(da[i]==db[i]){
			cnt++;
		}
		else if(da[i]+1==db[i]){
			S.insert(i);
		}
		else if(da[i]==db[i]+1){
			S2.insert(i);
		}
		else{
			cout<<0<<endl;
			return 0;
		}
	}
	
	if(S.size()==0&&S2.size()==0){
		cout<<cnt<<endl;
		return 0;
	}
	if(S.size()==1&&S2.size()==1){
		cout<<1<<endl;
		return 0;
	}
	
	cout<<0<<endl;
	
	return 0;
}
0