結果

問題 No.1492 01文字列と転倒
ユーザー phsplsphspls
提出日時 2023-01-24 02:11:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 577 ms / 4,000 ms
コード長 1,120 bytes
コンパイル時間 4,973 ms
コンパイル使用メモリ 145,912 KB
実行使用メモリ 9,764 KB
最終ジャッジ日時 2023-09-08 02:02:07
合計ジャッジ時間 8,946 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 577 ms
9,764 KB
testcase_03 AC 524 ms
9,312 KB
testcase_04 AC 499 ms
8,808 KB
testcase_05 AC 419 ms
8,076 KB
testcase_06 AC 439 ms
8,264 KB
testcase_07 AC 457 ms
8,572 KB
testcase_08 AC 546 ms
9,756 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 420 ms
8,260 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 8 ms
4,388 KB
testcase_17 AC 383 ms
8,092 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 326 ms
7,208 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `MOD` should have a snake case name
 --> Main.rs:7:9
  |
7 |     let MOD = nm[1];
  |         ^^^
  |
  = note: `#[warn(non_snake_case)]` on by default
help: rename the identifier or convert it to a snake case raw identifier
  |
7 |     let r#mod = nm[1];
  |         ~~~~~

warning: 1 warning emitted

ソースコード

diff #

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let MOD = nm[1];

    let limit = n * (n-1) / 2;
    let mut dp = vec![vec![0usize; limit+1]; n+1];
    dp[0][0] = 1;
    for total in 0..2*n {
        let mut next_dp = vec![vec![0usize; limit+1]; n+1];
        for cnt1 in 0..=n {
            for rval in 0..=limit {
                if dp[cnt1][rval] == 0 { continue; }
                let cnt0 = total - cnt1;
                if cnt0+1 <= n {
                    next_dp[cnt1][rval] += dp[cnt1][rval];
                    next_dp[cnt1][rval] %= MOD;
                }
                if cnt1+1 <= cnt0 {
                    let val = n - cnt0;
                    next_dp[cnt1+1][rval + val] += dp[cnt1][rval];
                    next_dp[cnt1+1][rval + val] %= MOD;
                }
            }
        }
        dp = next_dp;
    }
    for i in 0..=limit {
        println!("{}", dp[n][i]);
    }
    for _ in limit+1..=n*n {
        println!("0");
    }
}
0