結果

問題 No.1340 おーじ君をさがせ
ユーザー ikdikd
提出日時 2021-01-15 22:40:43
言語 Rust
(1.77.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 2,590 bytes
コンパイル時間 1,257 ms
コンパイル使用メモリ 153,348 KB
実行使用メモリ 7,396 KB
最終ジャッジ日時 2023-08-18 16:41:12
合計ジャッジ時間 8,267 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 70 ms
4,516 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 59 ms
4,376 KB
testcase_14 AC 167 ms
6,452 KB
testcase_15 AC 130 ms
5,832 KB
testcase_16 AC 10 ms
4,376 KB
testcase_17 AC 43 ms
4,380 KB
testcase_18 AC 87 ms
4,844 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 43 ms
4,376 KB
testcase_22 AC 109 ms
5,408 KB
testcase_23 AC 42 ms
4,376 KB
testcase_24 AC 207 ms
7,324 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 44 ms
4,376 KB
testcase_31 AC 207 ms
7,288 KB
testcase_32 AC 196 ms
7,132 KB
testcase_33 AC 204 ms
7,220 KB
testcase_34 AC 199 ms
6,976 KB
testcase_35 AC 196 ms
6,932 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 208 ms
7,328 KB
testcase_39 AC 201 ms
7,376 KB
testcase_40 AC 213 ms
7,396 KB
testcase_41 AC 215 ms
7,372 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 208 ms
7,328 KB
testcase_47 AC 200 ms
7,360 KB
testcase_48 AC 213 ms
7,396 KB
testcase_49 AC 206 ms
7,324 KB
testcase_50 AC 206 ms
7,188 KB
testcase_51 AC 204 ms
7,372 KB
testcase_52 AC 206 ms
7,288 KB
testcase_53 AC 204 ms
7,324 KB
testcase_54 AC 208 ms
7,392 KB
testcase_55 AC 213 ms
7,292 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 204 ms
7,328 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 210 ms
7,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let n: usize = rd.get();
    let m: usize = rd.get();
    let t: u64 = rd.get();

    let mut a = vec![vec![0; n]; n];
    for _ in 0..m {
        let u: usize = rd.get();
        let v: usize = rd.get();
        a[v][u] = 1;
    }
    let mut b = vec![vec![vec![0; n]; n]; 64];
    b[0] = a;
    for o in 0..63 {
        for i in 0..n {
            for j in 0..n {
                for k in 0..n {
                    b[o + 1][i][j] |= b[o][i][k] & b[o][k][j];
                }
            }
        }
    }
    let mut y = vec![0; n];
    y[0] = 1;
    for o in 0..64 {
        if t >> o & 1 == 1 {
            let mut nxt = vec![0; n];
            for i in 0..n {
                for j in 0..n {
                    nxt[i] |= b[o][i][j] & y[j];
                }
            }
            y = nxt;
        }
    }
    let ans = y.iter().sum::<usize>();
    println!("{}", ans);
}

pub struct ProconReader<R> {
    r: R,
    line: String,
    i: usize,
}

impl<R: std::io::BufRead> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self {
            r: reader,
            line: String::new(),
            i: 0,
        }
    }
    pub fn get<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        self.skip_blanks();
        assert!(self.i < self.line.len());
        assert_ne!(&self.line[self.i..=self.i], " ");
        let line = &self.line[self.i..];
        let end = line.find(' ').unwrap_or_else(|| line.len());
        let s = &line[..end];
        self.i += end;
        s.parse()
            .unwrap_or_else(|_| panic!("parse error `{}`", self.line))
    }
    fn skip_blanks(&mut self) {
        loop {
            let start = self.line[self.i..].find(|ch| ch != ' ');
            match start {
                Some(j) => {
                    self.i += j;
                    break;
                }
                None => {
                    self.line.clear();
                    self.i = 0;
                    let num_bytes = self.r.read_line(&mut self.line).unwrap();
                    assert!(num_bytes > 0, "reached EOF :(");
                    self.line = self.line.trim_end_matches(&['\r', '\n'][..]).to_string();
                }
            }
        }
    }

    pub fn get_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.get()).collect()
    }
}
0