結果

問題 No.1097 Remainder Operation
ユーザー StrorkisStrorkis
提出日時 2020-06-26 22:40:54
言語 Rust
(1.77.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 1,426 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 142,572 KB
実行使用メモリ 67,060 KB
最終ジャッジ日時 2023-09-18 06:17:29
合計ジャッジ時間 5,987 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 24 ms
8,492 KB
testcase_08 AC 24 ms
8,576 KB
testcase_09 AC 24 ms
8,536 KB
testcase_10 AC 24 ms
8,568 KB
testcase_11 AC 24 ms
8,572 KB
testcase_12 AC 241 ms
66,836 KB
testcase_13 AC 274 ms
66,832 KB
testcase_14 AC 274 ms
66,796 KB
testcase_15 AC 316 ms
66,864 KB
testcase_16 AC 253 ms
66,832 KB
testcase_17 AC 215 ms
66,848 KB
testcase_18 AC 215 ms
67,004 KB
testcase_19 AC 231 ms
67,052 KB
testcase_20 AC 228 ms
67,036 KB
testcase_21 AC 396 ms
67,060 KB
testcase_22 AC 400 ms
67,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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