結果

問題 No.1013 〇マス進む
ユーザー koba-e964koba-e964
提出日時 2020-03-20 22:03:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 2,925 bytes
コンパイル時間 13,043 ms
コンパイル使用メモリ 396,960 KB
実行使用メモリ 49,664 KB
最終ジャッジ日時 2024-05-08 22:06:35
合計ジャッジ時間 18,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 31 ms
24,704 KB
testcase_15 AC 58 ms
38,912 KB
testcase_16 AC 52 ms
35,840 KB
testcase_17 AC 28 ms
21,760 KB
testcase_18 AC 37 ms
26,240 KB
testcase_19 AC 21 ms
16,512 KB
testcase_20 AC 72 ms
47,104 KB
testcase_21 AC 25 ms
20,224 KB
testcase_22 AC 39 ms
27,136 KB
testcase_23 AC 12 ms
10,112 KB
testcase_24 AC 72 ms
48,896 KB
testcase_25 AC 69 ms
47,616 KB
testcase_26 AC 12 ms
10,240 KB
testcase_27 AC 23 ms
19,200 KB
testcase_28 AC 12 ms
10,240 KB
testcase_29 AC 66 ms
46,208 KB
testcase_30 AC 23 ms
17,280 KB
testcase_31 AC 42 ms
31,360 KB
testcase_32 AC 29 ms
23,680 KB
testcase_33 AC 33 ms
23,680 KB
testcase_34 AC 64 ms
36,736 KB
testcase_35 AC 69 ms
34,816 KB
testcase_36 AC 5 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 70 ms
40,320 KB
testcase_39 AC 24 ms
14,208 KB
testcase_40 AC 81 ms
36,480 KB
testcase_41 AC 14 ms
10,240 KB
testcase_42 AC 34 ms
22,912 KB
testcase_43 AC 21 ms
15,360 KB
testcase_44 AC 34 ms
23,936 KB
testcase_45 AC 31 ms
21,248 KB
testcase_46 AC 16 ms
11,136 KB
testcase_47 AC 32 ms
22,784 KB
testcase_48 AC 39 ms
26,496 KB
testcase_49 AC 82 ms
36,480 KB
testcase_50 AC 52 ms
31,360 KB
testcase_51 AC 46 ms
28,288 KB
testcase_52 AC 10 ms
7,168 KB
testcase_53 AC 12 ms
9,472 KB
testcase_54 AC 51 ms
34,560 KB
testcase_55 AC 18 ms
11,520 KB
testcase_56 AC 79 ms
43,392 KB
testcase_57 AC 65 ms
30,080 KB
testcase_58 AC 111 ms
49,536 KB
testcase_59 AC 97 ms
49,536 KB
testcase_60 AC 82 ms
49,536 KB
testcase_61 AC 64 ms
49,536 KB
testcase_62 AC 62 ms
49,664 KB
testcase_63 AC 1 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, k: i64,
        p: [usize; n],
    }
    const B: usize = 30;
    let mut dbl = vec![vec![(0i64, 0usize); n]; B];
    for i in 0..n {
        let to = i + p[i];
        dbl[0][i] = ((to / n) as i64, to % n);
    }
    for i in 1..B {
        for j in 0..n {
            let (x, y) = dbl[i - 1][j];
            let (z, t) = dbl[i - 1][y];
            dbl[i][j] = (x + z, t);
        }
    }
    for i in 0..n {
        let mut x = 0;
        let mut y = i;
        for j in 0..B {
            if (k & 1 << j) != 0 {
                let (a, b) = dbl[j][y];
                x += a;
                y = b;
            }
        }
        puts!("{}\n", x * n as i64 + y as i64 + 1);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}
0