結果

問題 No.483 マッチ並べ
ユーザー tanzakutanzaku
提出日時 2017-02-10 23:09:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,582 bytes
コンパイル時間 5,904 ms
コンパイル使用メモリ 76,476 KB
実行使用メモリ 56,456 KB
最終ジャッジ日時 2023-08-28 12:19:27
合計ジャッジ時間 17,474 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
55,716 KB
testcase_01 AC 134 ms
55,724 KB
testcase_02 AC 134 ms
55,628 KB
testcase_03 AC 138 ms
55,964 KB
testcase_04 AC 143 ms
55,772 KB
testcase_05 AC 139 ms
55,840 KB
testcase_06 AC 142 ms
55,728 KB
testcase_07 AC 144 ms
55,492 KB
testcase_08 AC 141 ms
55,736 KB
testcase_09 AC 138 ms
56,100 KB
testcase_10 AC 138 ms
55,768 KB
testcase_11 AC 138 ms
55,728 KB
testcase_12 AC 139 ms
55,508 KB
testcase_13 AC 136 ms
55,796 KB
testcase_14 AC 136 ms
55,736 KB
testcase_15 AC 142 ms
55,528 KB
testcase_16 AC 143 ms
55,728 KB
testcase_17 AC 146 ms
55,528 KB
testcase_18 AC 135 ms
55,864 KB
testcase_19 AC 140 ms
55,820 KB
testcase_20 AC 134 ms
55,508 KB
testcase_21 AC 139 ms
55,864 KB
testcase_22 AC 139 ms
55,996 KB
testcase_23 AC 141 ms
55,920 KB
testcase_24 AC 139 ms
55,484 KB
testcase_25 AC 138 ms
55,992 KB
testcase_26 AC 155 ms
55,740 KB
testcase_27 AC 178 ms
56,068 KB
testcase_28 AC 182 ms
56,100 KB
testcase_29 AC 166 ms
56,040 KB
testcase_30 AC 176 ms
56,032 KB
testcase_31 AC 173 ms
56,052 KB
testcase_32 AC 185 ms
56,016 KB
testcase_33 AC 144 ms
55,728 KB
testcase_34 AC 143 ms
56,084 KB
testcase_35 AC 141 ms
55,836 KB
testcase_36 AC 141 ms
55,668 KB
testcase_37 AC 151 ms
56,272 KB
testcase_38 AC 169 ms
56,072 KB
testcase_39 AC 167 ms
56,256 KB
testcase_40 AC 164 ms
56,012 KB
testcase_41 AC 172 ms
56,160 KB
testcase_42 AC 173 ms
55,808 KB
testcase_43 AC 179 ms
55,988 KB
testcase_44 AC 142 ms
55,516 KB
testcase_45 AC 145 ms
56,028 KB
testcase_46 AC 144 ms
55,728 KB
testcase_47 AC 156 ms
55,924 KB
testcase_48 AC 168 ms
56,064 KB
testcase_49 AC 159 ms
56,056 KB
testcase_50 AC 169 ms
55,756 KB
testcase_51 AC 158 ms
56,456 KB
testcase_52 AC 168 ms
56,000 KB
testcase_53 AC 133 ms
55,768 KB
testcase_54 AC 139 ms
55,760 KB
testcase_55 AC 142 ms
56,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.Map.Entry;

public class _483 {
	public static void main(String[] args) throws IOException {
		new _483().solve();
	}

	void solve() throws IOException {
		try (final Scanner in = new Scanner(System.in)) {
			int n = in.nextInt();
			TreeMap<Integer, TreeSet<Integer>> g = new TreeMap<>();
			for (int i = 0; i < n; i++) {
				int x1 = in.nextInt();
				int y1 = in.nextInt();
				int x2 = in.nextInt();
				int y2 = in.nextInt();
				int k1 = x1 * 200 + y1;
				int k2 = x2 * 200 + y2;
				TreeSet<Integer> es1 = g.getOrDefault(k1, new TreeSet<>());
				TreeSet<Integer> es2 = g.getOrDefault(k2, new TreeSet<>());
				es1.add(k2);
				es2.add(k1);
				g.put(k1, es1);
				g.put(k2, es2);
			}
			TreeMap<Integer, Integer> deg = new TreeMap<>();
			for (Entry<Integer, TreeSet<Integer>> e : g.entrySet()) {
				deg.put(e.getKey(), e.getValue().size());
			}
			while (true) {
				TreeSet<Integer> ks = new TreeSet<>(g.keySet());
				boolean updated = false;
				boolean all2 = true;
				for (int k : ks) {
					all2 &= g.get(k).size() == 2 || g.get(k).size() == 0;
					if (g.get(k).size() == 1) {
						g.get(g.get(k).first()).remove(k);
						g.remove(k);
						updated = true;
					}
				}
//				dump(all2, updated);
				if (!updated) {
					System.out.println(all2 ? "YES" : "NO");
					break;
				}
			}
		}
	}
	
	// for debug
	static void dump(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}
}
0