結果

問題 No.657 テトラナッチ数列 Easy
ユーザー cra77756176
提出日時 2022-12-26 21:41:03
言語 Rust
(1.83.0 + proconio)
結果
RE  
実行時間 -
コード長 809 bytes
コンパイル時間 15,690 ms
コンパイル使用メモリ 404,524 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-21 07:51:51
合計ジャッジ時間 14,654 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 RE * 1
other AC * 9 RE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

fn main() {
    let mut xx = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut xx).ok();
    let xx: Vec<usize> = xx.split_whitespace().skip(1).flat_map(str::parse).collect();

    let mut xx_sorted = xx.clone();
    xx_sorted.sort_unstable();
    xx_sorted.dedup();
    let xx_sorted = xx_sorted;

    let n_max = *xx.iter().max().unwrap();

    let mut values: HashMap<usize, i32> = [(1, 0), (2, 0), (3, 0), (4, 1)].into_iter().collect();
    let mut t = (0, 0, 0, 1);
    let mut i_xx = 0;
    for i in 5..=n_max {
        t = (t.1, t.2, t.3, (t.0 + t.1 + t.2 + t.3) % 17);
        if i == xx_sorted[i_xx] {
            values.insert(i, t.3);
            i_xx += 1;
        }
    }

    for &n in &xx {
        println!("{}", values[&n]);
    }
}
0