結果

問題 No.1097 Remainder Operation
コンテスト
ユーザー Strorkis
提出日時 2020-06-26 22:40:54
言語 Rust
(1.93.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 1,426 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 939 ms
コンパイル使用メモリ 196,284 KB
実行使用メモリ 67,328 KB
最終ジャッジ日時 2026-03-26 05:02:49
合計ジャッジ時間 4,525 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut next: Vec<Vec<[usize; 2]>> = vec![vec![[0; 2]; n]; 41];
    for j in 0..n {
        next[0][j] = [(j + a[j]) % n, a[j]];
    }
    for i in 1..41 {
        for j in 0..n {
            next[i][j] = {
                [
                    next[i - 1][next[i - 1][j][0]][0],
                    next[i - 1][j][1] + next[i - 1][next[i - 1][j][0]][1],
                ]
            }
        }
    }

    let q: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    for _ in 0..q {
        let k: usize = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            buf.trim_end().parse().unwrap()
        };
       
        let mut ans = 0;
        let mut now = 0;
        for i in (0..41).rev() {
            if (k & 1 << i) > 0 {
                ans += next[i][now][1];
                now = next[i][now][0];
            }
        }
        println!("{}", ans);
    }
}
0