結果

問題 No.1605 Matrix Shape
ユーザー 夜
提出日時 2021-07-16 22:21:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 983 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 98,628 KB
実行使用メモリ 16,076 KB
最終ジャッジ日時 2023-09-20 14:34:30
合計ジャッジ時間 5,491 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 224 ms
16,076 KB
testcase_20 AC 163 ms
10,316 KB
testcase_21 AC 162 ms
10,312 KB
testcase_22 WA -
testcase_23 AC 222 ms
16,044 KB
testcase_24 AC 218 ms
15,864 KB
testcase_25 AC 86 ms
4,932 KB
testcase_26 AC 87 ms
4,880 KB
testcase_27 AC 87 ms
5,168 KB
testcase_28 WA -
testcase_29 AC 86 ms
4,932 KB
testcase_30 AC 160 ms
10,464 KB
testcase_31 AC 161 ms
10,324 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 167 ms
13,464 KB
testcase_36 AC 92 ms
9,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int h[200020], w[200020];
int l[200020] = {}, r[200020] = {};
set<int> st;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i] >> w[i];
		if (h[i] == w[i]) {
			l[h[i]]++;
			r[w[i]]++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (h[i] != w[i]) {
			st.insert(h[i]);
			int m = l[w[i]];
			if (r[h[i]] == 0) {
				l[h[i]]++;
			}
			else {
				r[h[i]]--;
			}
			if (m == 0) {
				r[w[i]]++;
			}
			else {
				l[w[i]]--;
			}
		}
	}
	int l1 = 0, r1 = 0;
	for (int i = 1; i <= 200000; i++) {
		l1 += l[i];
		r1 += r[i];
	}
	if (l1 == 0 && r1 == 0) {
		cout << st.size() << endl;
	}
	else if (l1 == 1 && r1 == 1) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}
0