結果

問題 No.1340 おーじ君をさがせ
ユーザー tentententen
提出日時 2023-06-07 09:22:32
言語 Java
(openjdk 23)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 3,439 bytes
コンパイル時間 5,506 ms
コンパイル使用メモリ 83,944 KB
実行使用メモリ 43,468 KB
最終ジャッジ日時 2024-12-29 15:09:25
合計ジャッジ時間 12,568 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
37,184 KB
testcase_01 AC 57 ms
36,680 KB
testcase_02 AC 57 ms
36,992 KB
testcase_03 AC 60 ms
36,848 KB
testcase_04 AC 59 ms
36,668 KB
testcase_05 AC 59 ms
37,044 KB
testcase_06 AC 59 ms
36,680 KB
testcase_07 AC 57 ms
36,816 KB
testcase_08 AC 60 ms
36,736 KB
testcase_09 AC 60 ms
36,800 KB
testcase_10 AC 63 ms
37,180 KB
testcase_11 AC 90 ms
38,484 KB
testcase_12 AC 76 ms
37,580 KB
testcase_13 AC 81 ms
38,344 KB
testcase_14 AC 97 ms
38,796 KB
testcase_15 AC 94 ms
38,528 KB
testcase_16 AC 66 ms
37,248 KB
testcase_17 AC 73 ms
38,520 KB
testcase_18 AC 92 ms
38,596 KB
testcase_19 AC 61 ms
37,080 KB
testcase_20 AC 57 ms
36,792 KB
testcase_21 AC 164 ms
40,860 KB
testcase_22 AC 163 ms
40,808 KB
testcase_23 AC 167 ms
41,196 KB
testcase_24 AC 165 ms
40,560 KB
testcase_25 AC 153 ms
41,996 KB
testcase_26 AC 135 ms
40,836 KB
testcase_27 AC 141 ms
40,048 KB
testcase_28 AC 156 ms
41,212 KB
testcase_29 AC 128 ms
39,952 KB
testcase_30 AC 171 ms
40,848 KB
testcase_31 AC 191 ms
41,788 KB
testcase_32 AC 188 ms
41,560 KB
testcase_33 AC 182 ms
41,576 KB
testcase_34 AC 194 ms
43,468 KB
testcase_35 AC 192 ms
41,704 KB
testcase_36 AC 61 ms
37,028 KB
testcase_37 AC 146 ms
40,912 KB
testcase_38 AC 176 ms
41,280 KB
testcase_39 AC 192 ms
41,928 KB
testcase_40 AC 195 ms
41,804 KB
testcase_41 AC 203 ms
41,900 KB
testcase_42 AC 64 ms
37,324 KB
testcase_43 AC 60 ms
36,680 KB
testcase_44 AC 58 ms
36,796 KB
testcase_45 AC 58 ms
36,940 KB
testcase_46 AC 145 ms
40,668 KB
testcase_47 AC 153 ms
40,576 KB
testcase_48 AC 150 ms
40,660 KB
testcase_49 AC 113 ms
39,008 KB
testcase_50 AC 106 ms
38,944 KB
testcase_51 AC 112 ms
39,092 KB
testcase_52 AC 103 ms
38,740 KB
testcase_53 AC 100 ms
38,804 KB
testcase_54 AC 99 ms
38,932 KB
testcase_55 AC 131 ms
40,292 KB
testcase_56 AC 56 ms
37,080 KB
testcase_57 AC 58 ms
36,968 KB
testcase_58 AC 58 ms
37,088 KB
testcase_59 AC 101 ms
38,720 KB
testcase_60 AC 61 ms
37,196 KB
testcase_61 AC 103 ms
38,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0