結果

問題 No.1492 01文字列と転倒
ユーザー koba-e964koba-e964
提出日時 2021-10-15 09:15:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 873 ms / 4,000 ms
コード長 1,479 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 172,256 KB
実行使用メモリ 9,692 KB
最終ジャッジ日時 2023-10-17 19:34:12
合計ジャッジ時間 8,583 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 873 ms
9,692 KB
testcase_03 AC 803 ms
9,256 KB
testcase_04 AC 731 ms
8,740 KB
testcase_05 AC 614 ms
8,036 KB
testcase_06 AC 644 ms
8,212 KB
testcase_07 AC 709 ms
8,608 KB
testcase_08 AC 868 ms
9,692 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 639 ms
8,212 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 610 ms
8,036 KB
testcase_18 AC 12 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 7 ms
4,348 KB
testcase_21 AC 509 ms
7,156 KB
testcase_22 AC 10 ms
4,348 KB
testcase_23 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
    let n: usize = get();
    let m: i64 = get();
    let lim = n * (n - 1) / 2 + 1;
    let mut dp = vec![vec![0; lim]; n + 1];
    dp[0][0] = 1;
    for i in 0..2 * n {
        let mut ep = vec![vec![0; lim]; n + 1];
        for j in 0..n + 1 {
            if j > i + 1 { continue; }
            if (i + 1 + j) % 2 != 0 { continue; }
            let opp = (i + 1 - j) / 2;
            for k in 0..lim {
                if j > 0 && k >= opp {
                    ep[j][k] += dp[j - 1][k - opp];
                    ep[j][k] %= m;
                }
                if j < n {
                    ep[j][k] += dp[j + 1][k];
                    ep[j][k] %= m;
                }
            }
        }
        dp = ep;
    }
    for i in 0..n * n + 1 {
        println!("{}", if i >= lim { 0 } else { dp[0][i] });
    }
}
0