結果

問題 No.1340 おーじ君をさがせ
ユーザー ks2mks2m
提出日時 2021-01-15 22:33:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,104 ms / 2,000 ms
コード長 1,679 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 78,748 KB
実行使用メモリ 76,556 KB
最終ジャッジ日時 2024-05-05 21:50:54
合計ジャッジ時間 20,418 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,276 KB
testcase_01 AC 45 ms
37,148 KB
testcase_02 AC 46 ms
36,532 KB
testcase_03 AC 47 ms
36,840 KB
testcase_04 AC 53 ms
36,804 KB
testcase_05 AC 52 ms
37,104 KB
testcase_06 AC 48 ms
36,676 KB
testcase_07 AC 54 ms
36,668 KB
testcase_08 AC 49 ms
36,924 KB
testcase_09 AC 50 ms
37,088 KB
testcase_10 AC 91 ms
39,400 KB
testcase_11 AC 84 ms
39,268 KB
testcase_12 AC 137 ms
42,924 KB
testcase_13 AC 50 ms
37,356 KB
testcase_14 AC 79 ms
39,148 KB
testcase_15 AC 57 ms
37,576 KB
testcase_16 AC 138 ms
42,344 KB
testcase_17 AC 52 ms
37,604 KB
testcase_18 AC 53 ms
37,484 KB
testcase_19 AC 49 ms
37,276 KB
testcase_20 AC 99 ms
39,876 KB
testcase_21 AC 429 ms
55,240 KB
testcase_22 AC 625 ms
60,532 KB
testcase_23 AC 420 ms
55,072 KB
testcase_24 AC 1,072 ms
76,556 KB
testcase_25 AC 208 ms
44,320 KB
testcase_26 AC 178 ms
43,440 KB
testcase_27 AC 180 ms
42,888 KB
testcase_28 AC 234 ms
44,924 KB
testcase_29 AC 144 ms
41,256 KB
testcase_30 AC 433 ms
55,136 KB
testcase_31 AC 1,104 ms
74,412 KB
testcase_32 AC 150 ms
43,648 KB
testcase_33 AC 144 ms
43,828 KB
testcase_34 AC 385 ms
53,888 KB
testcase_35 AC 394 ms
53,908 KB
testcase_36 AC 48 ms
36,968 KB
testcase_37 AC 134 ms
41,988 KB
testcase_38 AC 140 ms
43,432 KB
testcase_39 AC 1,007 ms
73,596 KB
testcase_40 AC 1,003 ms
73,512 KB
testcase_41 AC 1,002 ms
73,584 KB
testcase_42 AC 48 ms
37,112 KB
testcase_43 AC 46 ms
37,116 KB
testcase_44 AC 46 ms
36,844 KB
testcase_45 AC 46 ms
37,028 KB
testcase_46 AC 701 ms
71,988 KB
testcase_47 AC 744 ms
70,912 KB
testcase_48 AC 747 ms
71,340 KB
testcase_49 AC 781 ms
69,908 KB
testcase_50 AC 888 ms
69,960 KB
testcase_51 AC 938 ms
71,148 KB
testcase_52 AC 92 ms
39,744 KB
testcase_53 AC 87 ms
39,448 KB
testcase_54 AC 79 ms
39,588 KB
testcase_55 AC 397 ms
58,184 KB
testcase_56 AC 50 ms
37,148 KB
testcase_57 AC 50 ms
36,972 KB
testcase_58 AC 46 ms
37,208 KB
testcase_59 AC 88 ms
39,932 KB
testcase_60 AC 45 ms
37,076 KB
testcase_61 AC 90 ms
40,128 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 {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		long t = Long.parseLong(sa[2]);
		List<List<Integer>> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]);
			int b = Integer.parseInt(sa[1]);
			list.get(a).add(b);
		}
		br.close();

		int e = 63;
		List<List<Set<Integer>>> dp = new ArrayList<>(e);
		List<Set<Integer>> wk = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			Set<Integer> set = new HashSet<>();
			set.addAll(list.get(i));
			wk.add(set);
		}
		dp.add(wk);
		for (int i = 1; i < e; i++) {
			wk = new ArrayList<>(n);
			List<Set<Integer>> pre = dp.get(i - 1);
			for (int j = 0; j < n; j++) {
				Set<Integer> set = new HashSet<>();
				Set<Integer> ps = pre.get(j);
				for (int k : ps) {
					set.addAll(pre.get(k));
				}
				wk.add(set);
			}
			dp.add(wk);
		}

		Set<Integer> ans = new HashSet<>();
		ans.add(0);
		for (int i = 0; i < e; i++) {
			if ((t >> i & 1) == 0) {
				continue;
			}
			Set<Integer> set = new HashSet<>();
			List<Set<Integer>> di = dp.get(i);
			for (int k : ans) {
				set.addAll(di.get(k));
			}
			ans = set;
			if (ans.size() == n) {
				break;
			}
		}
		System.out.println(ans.size());
	}
}
0