結果

問題 No.657 テトラナッチ数列 Easy
ユーザー cra77756176cra77756176
提出日時 2022-12-26 21:45:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 11,729 ms
コンパイル使用メモリ 391,508 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 06:12:01
合計ジャッジ時間 12,682 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 0 ms
6,816 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 4 ms
6,816 KB
testcase_05 AC 12 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 0 ms
6,940 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 12 ms
6,944 KB
testcase_10 AC 14 ms
6,940 KB
testcase_11 AC 13 ms
6,940 KB
testcase_12 AC 14 ms
6,944 KB
testcase_13 AC 18 ms
6,944 KB
testcase_14 AC 17 ms
6,944 KB
testcase_15 AC 19 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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.retain(|&n| n > 4);
    xx_sorted.sort_unstable();
    xx_sorted.dedup();
    let xx_sorted = xx_sorted;

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

    let mut values = HashMap::new();
    values.extend([(1, 0), (2, 0), (3, 0), (4, 1)]);
    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