結果

問題 No.1512 作文
ユーザー phsplsphspls
提出日時 2022-11-03 13:55:22
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 149,508 KB
実行使用メモリ 62,816 KB
最終ジャッジ日時 2023-09-24 23:18:57
合計ジャッジ時間 5,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

const SIZE: usize = 26;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let words = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp = temp.trim();
            temp.chars().collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let mut words = words.iter().filter(|&v| {
            let mut temp = v.clone().to_owned();
            temp.sort();
            v == &temp
        })
        .collect::<Vec<_>>();
    words.sort_by_key(|&v| v[v.len()-1]);
    let n = words.len();
    let mut dp = vec![vec![0usize; SIZE]; n+1];
    for i in 0..n {
        let start = words[i][0] as usize - 'a' as usize;
        let end = words[i][words[i].len()-1] as usize - 'a' as usize;
        let val = words[i].len();
        for j in 0..SIZE {
            dp[i+1][j] = dp[i+1][j].max(dp[i][j]);
            if j > 0 {
                dp[i+1][j] = dp[i+1][j].max(dp[i+1][j-1]);
            }
            if j <= start {
                dp[i+1][end] = dp[i+1][end].max(dp[i][j] + val);
            }
        }
    }
    println!("{}", dp[n][SIZE-1]);
}
0