結果
問題 | No.1340 おーじ君をさがせ |
ユーザー | tenten |
提出日時 | 2023-06-07 09:22:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 167 ms / 2,000 ms |
コード長 | 3,439 bytes |
コンパイル時間 | 2,727 ms |
コンパイル使用メモリ | 90,564 KB |
実行使用メモリ | 57,428 KB |
最終ジャッジ日時 | 2024-06-09 09:22:45 |
合計ジャッジ時間 | 9,643 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
49,968 KB |
testcase_01 | AC | 48 ms
50,048 KB |
testcase_02 | AC | 47 ms
50,496 KB |
testcase_03 | AC | 48 ms
50,416 KB |
testcase_04 | AC | 49 ms
50,084 KB |
testcase_05 | AC | 48 ms
50,444 KB |
testcase_06 | AC | 48 ms
50,276 KB |
testcase_07 | AC | 48 ms
49,924 KB |
testcase_08 | AC | 47 ms
50,500 KB |
testcase_09 | AC | 48 ms
50,312 KB |
testcase_10 | AC | 54 ms
50,644 KB |
testcase_11 | AC | 86 ms
51,624 KB |
testcase_12 | AC | 75 ms
51,220 KB |
testcase_13 | AC | 64 ms
51,544 KB |
testcase_14 | AC | 83 ms
51,780 KB |
testcase_15 | AC | 82 ms
51,672 KB |
testcase_16 | AC | 61 ms
50,504 KB |
testcase_17 | AC | 81 ms
51,284 KB |
testcase_18 | AC | 67 ms
51,400 KB |
testcase_19 | AC | 52 ms
50,520 KB |
testcase_20 | AC | 52 ms
50,452 KB |
testcase_21 | AC | 144 ms
55,764 KB |
testcase_22 | AC | 139 ms
54,416 KB |
testcase_23 | AC | 137 ms
55,020 KB |
testcase_24 | AC | 130 ms
53,388 KB |
testcase_25 | AC | 117 ms
54,252 KB |
testcase_26 | AC | 118 ms
52,684 KB |
testcase_27 | AC | 112 ms
51,952 KB |
testcase_28 | AC | 125 ms
54,504 KB |
testcase_29 | AC | 102 ms
52,268 KB |
testcase_30 | AC | 139 ms
56,668 KB |
testcase_31 | AC | 167 ms
56,744 KB |
testcase_32 | AC | 148 ms
54,652 KB |
testcase_33 | AC | 149 ms
54,820 KB |
testcase_34 | AC | 145 ms
54,664 KB |
testcase_35 | AC | 149 ms
55,068 KB |
testcase_36 | AC | 49 ms
50,464 KB |
testcase_37 | AC | 115 ms
54,524 KB |
testcase_38 | AC | 143 ms
56,780 KB |
testcase_39 | AC | 160 ms
57,428 KB |
testcase_40 | AC | 160 ms
54,880 KB |
testcase_41 | AC | 154 ms
55,068 KB |
testcase_42 | AC | 50 ms
50,344 KB |
testcase_43 | AC | 48 ms
50,184 KB |
testcase_44 | AC | 48 ms
50,528 KB |
testcase_45 | AC | 49 ms
50,448 KB |
testcase_46 | AC | 112 ms
53,048 KB |
testcase_47 | AC | 110 ms
53,020 KB |
testcase_48 | AC | 111 ms
52,932 KB |
testcase_49 | AC | 92 ms
52,400 KB |
testcase_50 | AC | 91 ms
51,976 KB |
testcase_51 | AC | 91 ms
52,432 KB |
testcase_52 | AC | 87 ms
51,828 KB |
testcase_53 | AC | 84 ms
52,264 KB |
testcase_54 | AC | 86 ms
51,676 KB |
testcase_55 | AC | 111 ms
53,000 KB |
testcase_56 | AC | 50 ms
49,932 KB |
testcase_57 | AC | 51 ms
50,136 KB |
testcase_58 | AC | 51 ms
50,428 KB |
testcase_59 | AC | 88 ms
51,868 KB |
testcase_60 | AC | 50 ms
50,264 KB |
testcase_61 | AC | 91 ms
51,572 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long t = sc.nextLong(); BitSet[][] graph = new BitSet[60][n]; for (int i = 0; i < n; i++) { graph[0][i] = new BitSet(); } for (int i = 0; i < m; i++) { graph[0][sc.nextInt()].add(sc.nextInt()); } for (int i = 1; i < 60; i++) { for (int j = 0; j < n; j++) { graph[i][j] = new BitSet(); } for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if (graph[i - 1][j].get(k)) { graph[i][j].or(graph[i - 1][k]); } } } } BitSet ans = new BitSet(); ans.add(0); for (int i = 59; i >= 0; i--) { if (t < (1L << i)) { continue; } t -= (1L << i); BitSet next = new BitSet(); for (int j = 0; j < n; j++) { if (ans.get(j)) { next.or(graph[i][j]); } } ans = next; } System.out.println(ans.getCount()); } static class BitSet { long[] values = new long[2]; public void add(int x) { values[x / 60] |= (1L << (x % 60)); } public boolean get(int x) { return (values[x / 60] & (1L << (x % 60))) > 0; } public void or(BitSet x) { for (int i = 0; i < 2; i++) { values[i] |= x.values[i]; } } public int getCount() { long pop = 0; for (long x : values) { pop += getPop(x); } return (int)pop; } private long getPop(long x) { long pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return pop; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }