結果

問題 No.483 マッチ並べ
ユーザー 37zigen37zigen
提出日時 2017-02-11 04:45:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,459 bytes
コンパイル時間 3,780 ms
コンパイル使用メモリ 73,932 KB
実行使用メモリ 56,452 KB
最終ジャッジ日時 2023-08-28 12:46:19
合計ジャッジ時間 12,106 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,064 KB
testcase_01 AC 126 ms
55,684 KB
testcase_02 AC 129 ms
56,176 KB
testcase_03 AC 131 ms
55,356 KB
testcase_04 AC 131 ms
56,080 KB
testcase_05 AC 134 ms
53,552 KB
testcase_06 AC 130 ms
55,796 KB
testcase_07 AC 132 ms
55,832 KB
testcase_08 AC 132 ms
56,008 KB
testcase_09 AC 130 ms
55,960 KB
testcase_10 AC 132 ms
55,772 KB
testcase_11 AC 128 ms
55,928 KB
testcase_12 AC 131 ms
56,116 KB
testcase_13 AC 133 ms
56,148 KB
testcase_14 AC 131 ms
55,788 KB
testcase_15 AC 134 ms
55,856 KB
testcase_16 AC 132 ms
55,812 KB
testcase_17 AC 132 ms
55,560 KB
testcase_18 AC 124 ms
55,872 KB
testcase_19 AC 135 ms
54,184 KB
testcase_20 AC 127 ms
53,688 KB
testcase_21 AC 131 ms
56,020 KB
testcase_22 AC 127 ms
55,720 KB
testcase_23 AC 130 ms
55,728 KB
testcase_24 AC 128 ms
55,604 KB
testcase_25 AC 132 ms
55,800 KB
testcase_26 AC 145 ms
55,712 KB
testcase_27 AC 151 ms
55,980 KB
testcase_28 AC 152 ms
55,552 KB
testcase_29 AC 149 ms
56,028 KB
testcase_30 AC 152 ms
55,560 KB
testcase_31 AC 156 ms
55,804 KB
testcase_32 AC 164 ms
56,124 KB
testcase_33 AC 137 ms
55,996 KB
testcase_34 AC 135 ms
55,996 KB
testcase_35 AC 136 ms
55,772 KB
testcase_36 AC 136 ms
55,812 KB
testcase_37 AC 141 ms
55,776 KB
testcase_38 AC 152 ms
55,856 KB
testcase_39 AC 151 ms
56,180 KB
testcase_40 AC 154 ms
55,752 KB
testcase_41 AC 149 ms
56,452 KB
testcase_42 AC 150 ms
55,632 KB
testcase_43 AC 155 ms
55,892 KB
testcase_44 AC 132 ms
56,024 KB
testcase_45 AC 135 ms
56,204 KB
testcase_46 AC 133 ms
55,832 KB
testcase_47 AC 141 ms
56,068 KB
testcase_48 AC 147 ms
55,808 KB
testcase_49 AC 145 ms
55,656 KB
testcase_50 AC 150 ms
55,888 KB
testcase_51 AC 142 ms
55,844 KB
testcase_52 AC 149 ms
55,948 KB
testcase_53 AC 126 ms
56,356 KB
testcase_54 AC 129 ms
55,892 KB
testcase_55 AC 130 ms
56,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static int N;
	static int[] r0, c0, r1, c1;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		r0 = new int[N];
		c0 = new int[N];
		r1 = new int[N];
		c1 = new int[N];
		DJSet ds = new DJSet(100 * 100);
		for (int i = 0; i < N; ++i) {
			r0[i] = sc.nextInt() - 1;
			c0[i] = sc.nextInt() - 1;
			r1[i] = sc.nextInt() - 1;
			c1[i] = sc.nextInt() - 1;
			ds.setUnion(r0[i] + c0[i] * 100, r1[i] + c1[i] * 100);
		}
		for (int i = 0; i < 100; ++i) {
			for (int j = 0; j < 100; ++j) {
				if (ds.edgeNumber[ds.root(i + j * 100)] >= -ds.upper[ds.root(i + j * 100)] + 1) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}

	static class DJSet {
		int n;
		int[] upper;
		int[] edgeNumber;

		public DJSet(int n) {
			this.n = n;
			upper = new int[n];
			edgeNumber = new int[n];
			Arrays.fill(upper, -1);
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		void setUnion(int x, int y) {
			x = root(x);
			y = root(y);

			if (x != y) {
				if (upper[x] < upper[y]) {
					int tmp = x;
					x = y;
					y = tmp;
				}
				upper[y] += upper[x];
				upper[x] = y;
				edgeNumber[y] += edgeNumber[x];
			}
			++edgeNumber[y];
		}

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0