結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー tonyu0
提出日時 2020-05-29 23:55:28
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 907 bytes
コンパイル時間 13,680 ms
コンパイル使用メモリ 383,956 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-06 09:12:47
合計ジャッジ時間 14,946 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
const MOD: usize = 998244353;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let q: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse::<usize>().unwrap() - 1)
        .collect();
    let b: Vec<usize> = (0..q)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut dp: Vec<usize> = vec![0; n + 1];
    dp[0] = 1;
    for i in 0..n {
        let mut next = vec![0; n + 1];
        for j in 0..n {
            next[j + 1] += dp[j];
            next[j + 1] %= MOD;
            next[j] += dp[j] * a[i];
            next[j] %= MOD;
        }
        dp = next;
    }

    for i in 0..q {
        println!("{}", dp[b[i]]);
    }
}
0