結果

問題 No.1605 Matrix Shape
コンテスト
ユーザー ygussany
提出日時 2021-07-16 21:40:13
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 668 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 184 ms
コンパイル使用メモリ 38,624 KB
最終ジャッジ日時 2026-02-22 07:33:26
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 12 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, N, H, W, num[3][200001] = {}, ans = 0, count = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d %d", &H, &W);
		if (H == W) num[2][H]++;
		num[0][H]++;
		num[1][W]++;
	}
	for (i = 1; i <= 200000; i++) {
		if (num[0][i] == num[1][i]) {
			if (num[0][i] == num[2][i]) {
				if (num[0][i] == N) ans = 2;
				else ans = -1;
				break;
			}
			if (num[0][i] > 0) count++;
			continue;
		} else if (abs(num[0][i] - num[1][i]) == 1) ans++;
		else {
			ans = -1;
			break;
		}
	}
	if (ans == 0) printf("%d\n", count);
	else if (ans == 2) printf("1\n");
	else printf("0\n");
	fflush(stdout);
	return 0;
}
0