結果
| 問題 | 
                            No.1097 Remainder Operation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Strorkis
                         | 
                    
| 提出日時 | 2020-06-26 22:40:54 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 387 ms / 2,000 ms | 
| コード長 | 1,426 bytes | 
| コンパイル時間 | 13,757 ms | 
| コンパイル使用メモリ | 380,036 KB | 
| 実行使用メモリ | 67,072 KB | 
| 最終ジャッジ日時 | 2024-07-04 22:31:37 | 
| 合計ジャッジ時間 | 17,088 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 21 | 
ソースコード
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);
    }
}
            
            
            
        
            
Strorkis