結果

問題 No.1340 おーじ君をさがせ
ユーザー tentententen
提出日時 2023-06-07 09:22:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 3,439 bytes
コンパイル時間 3,764 ms
コンパイル使用メモリ 86,744 KB
実行使用メモリ 57,092 KB
最終ジャッジ日時 2023-08-28 14:10:42
合計ジャッジ時間 11,572 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,212 KB
testcase_01 AC 46 ms
49,460 KB
testcase_02 AC 45 ms
49,356 KB
testcase_03 AC 46 ms
47,852 KB
testcase_04 AC 45 ms
49,240 KB
testcase_05 AC 46 ms
49,724 KB
testcase_06 AC 45 ms
49,464 KB
testcase_07 AC 46 ms
49,404 KB
testcase_08 AC 46 ms
49,212 KB
testcase_09 AC 45 ms
49,588 KB
testcase_10 AC 49 ms
49,256 KB
testcase_11 AC 64 ms
51,616 KB
testcase_12 AC 61 ms
51,408 KB
testcase_13 AC 65 ms
51,520 KB
testcase_14 AC 80 ms
52,484 KB
testcase_15 AC 79 ms
50,520 KB
testcase_16 AC 59 ms
51,628 KB
testcase_17 AC 61 ms
50,712 KB
testcase_18 AC 77 ms
52,180 KB
testcase_19 AC 49 ms
49,536 KB
testcase_20 AC 49 ms
49,732 KB
testcase_21 AC 140 ms
57,092 KB
testcase_22 AC 144 ms
53,868 KB
testcase_23 AC 141 ms
54,976 KB
testcase_24 AC 127 ms
53,040 KB
testcase_25 AC 128 ms
56,304 KB
testcase_26 AC 107 ms
51,912 KB
testcase_27 AC 119 ms
52,496 KB
testcase_28 AC 135 ms
56,740 KB
testcase_29 AC 105 ms
52,192 KB
testcase_30 AC 144 ms
57,056 KB
testcase_31 AC 165 ms
55,284 KB
testcase_32 AC 151 ms
56,976 KB
testcase_33 AC 150 ms
54,928 KB
testcase_34 AC 155 ms
54,992 KB
testcase_35 AC 157 ms
56,756 KB
testcase_36 AC 46 ms
49,304 KB
testcase_37 AC 112 ms
54,752 KB
testcase_38 AC 150 ms
54,564 KB
testcase_39 AC 167 ms
54,832 KB
testcase_40 AC 163 ms
54,932 KB
testcase_41 AC 167 ms
55,044 KB
testcase_42 AC 45 ms
49,720 KB
testcase_43 AC 47 ms
47,228 KB
testcase_44 AC 48 ms
49,488 KB
testcase_45 AC 47 ms
49,584 KB
testcase_46 AC 113 ms
52,692 KB
testcase_47 AC 116 ms
52,620 KB
testcase_48 AC 118 ms
52,704 KB
testcase_49 AC 92 ms
52,688 KB
testcase_50 AC 93 ms
52,412 KB
testcase_51 AC 89 ms
52,484 KB
testcase_52 AC 87 ms
52,380 KB
testcase_53 AC 87 ms
52,320 KB
testcase_54 AC 85 ms
52,072 KB
testcase_55 AC 108 ms
52,800 KB
testcase_56 AC 46 ms
49,228 KB
testcase_57 AC 46 ms
49,228 KB
testcase_58 AC 46 ms
49,356 KB
testcase_59 AC 87 ms
52,288 KB
testcase_60 AC 46 ms
49,476 KB
testcase_61 AC 85 ms
50,296 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