結果

問題 No.1605 Matrix Shape
ユーザー ks2mks2m
提出日時 2021-07-16 22:42:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,650 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 75,016 KB
実行使用メモリ 108,212 KB
最終ジャッジ日時 2023-09-20 15:05:31
合計ジャッジ時間 18,664 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
64,760 KB
testcase_01 AC 121 ms
64,680 KB
testcase_02 AC 103 ms
64,664 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 123 ms
64,836 KB
testcase_06 AC 121 ms
64,584 KB
testcase_07 AC 104 ms
64,516 KB
testcase_08 AC 122 ms
64,920 KB
testcase_09 AC 112 ms
65,012 KB
testcase_10 AC 111 ms
64,924 KB
testcase_11 AC 105 ms
64,592 KB
testcase_12 AC 120 ms
64,512 KB
testcase_13 AC 111 ms
64,604 KB
testcase_14 AC 109 ms
64,976 KB
testcase_15 AC 104 ms
64,624 KB
testcase_16 AC 101 ms
64,968 KB
testcase_17 AC 103 ms
64,792 KB
testcase_18 AC 104 ms
64,072 KB
testcase_19 AC 787 ms
107,248 KB
testcase_20 AC 717 ms
103,444 KB
testcase_21 AC 699 ms
103,404 KB
testcase_22 WA -
testcase_23 AC 783 ms
107,948 KB
testcase_24 AC 715 ms
108,212 KB
testcase_25 AC 624 ms
96,616 KB
testcase_26 AC 616 ms
96,776 KB
testcase_27 AC 611 ms
96,644 KB
testcase_28 WA -
testcase_29 AC 597 ms
96,504 KB
testcase_30 AC 724 ms
101,280 KB
testcase_31 AC 706 ms
101,600 KB
testcase_32 AC 682 ms
99,096 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 637 ms
101,348 KB
testcase_36 AC 510 ms
94,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
	static int n;
	static List<Set<Hen>> list;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(br.readLine());
		int m = 200000;
		list = new ArrayList<>(m);
		for (int i = 0; i < m; i++) {
			list.add(new HashSet<>());
		}
		int[] in = new int[m];
		int[] out = new int[m];
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			Hen h = new Hen();
			h.a = Integer.parseInt(sa[0]) - 1;
			h.b = Integer.parseInt(sa[1]) - 1;
			if (h.a != h.b) {
				list.get(h.a).add(h);
				out[h.a]++;
				in[h.b]++;
			}
		}
		br.close();

		int s = -1;
		int t = -1;
		boolean even = false;
		for (int i = 0; i < m; i++) {
			if (in[i] != out[i]) {
				if (Math.abs(in[i] - out[i]) > 1) {
					System.out.println(0);
					return;
				}
				if (in[i] + 1 == out[i]) {
					if (s == -1) {
						s = i;
					} else {
						System.out.println(0);
						return;
					}
				} else {
					if (t == -1) {
						t = i;
					} else {
						System.out.println(0);
						return;
					}
				}
			}
		}
		if (s == -1) {
			for (int i = 0; i < m; i++) {
				if (out[i] > 0) {
					s = i;
					break;
				}
			}
			even = true;
		}
		if (even) {
			int ans = 0;
			for (int i = 0; i < m; i++) {
				if (!list.get(i).isEmpty()) {
					ans++;
				}
			}
			System.out.println(ans);
		} else {
			System.out.println(1);
		}
	}

	static class Hen {
		int a, b;
	}
}
0