結果

問題 No.1916 Making Palindrome on Gird
ユーザー hiromi_ayasehiromi_ayase
提出日時 2022-04-30 01:53:31
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,883 bytes
コンパイル時間 5,116 ms
コンパイル使用メモリ 152,620 KB
実行使用メモリ 812,240 KB
最終ジャッジ日時 2023-09-11 17:52:05
合計ジャッジ時間 5,949 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(clippy::many_single_char_names)]
fn main() {
    let s = getline();
    let a = s.split(' ').collect::<Vec<_>>();
    let h = a[0].parse::<usize>().unwrap();
    let w = a[1].parse::<usize>().unwrap();
    let mut s = vec![vec!['a'; w]; h];

    for i in 0..h {
        s[i] = getline().chars().collect();
    }

    let mut dp = vec![vec![vec![vec![0; w]; h]; w]; h];
    dp[0][0][h - 1][w - 1] = 1;

    let m = 1_000_000_007;

    for i in 0..h {
        for j in 0..w {
            for ni in (0..h).rev() {
                for nj in (0..w).rev() {
                    if ni < i || nj < j {
                        continue;
                    }
                    if i + 1 < ni && s[i + 1][j] == s[ni - 1][nj] {
                        dp[i + 1][j][ni - 1][nj] += dp[i][j][ni][nj];
                        dp[i + 1][j][ni - 1][nj] %= m;
                    }
                    if i < ni && j < nj && s[i + 1][j] == s[ni][nj - 1] {
                        dp[i + 1][j][ni][nj - 1] += dp[i][j][ni][nj];
                        dp[i + 1][j][ni][nj - 1] %= m;
                    }
                    if i < ni && j < nj && s[i][j + 1] == s[ni - 1][nj] {
                        dp[i][j + 1][ni - 1][nj] += dp[i][j][ni][nj];
                        dp[i][j + 1][ni - 1][nj] %= m;
                    }
                    if j + 1 < nj && s[i][j + 1] == s[ni][nj - 1] {
                        dp[i][j + 1][ni][nj - 1] += dp[i][j][ni][nj];
                        dp[i][j + 1][ni][nj - 1] %= m;
                    }
                }
            }
        }
    }
    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            ans += dp[i][j][i][j];
            ans %= m;
        }
    }
    println!("{}", ans);
}

fn getline() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_string()
}
0