結果

問題 No.1512 作文
ユーザー phsplsphspls
提出日時 2022-11-03 14:01:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 1,204 bytes
コンパイル時間 4,658 ms
コンパイル使用メモリ 149,808 KB
実行使用メモリ 62,760 KB
最終ジャッジ日時 2023-09-24 23:24:21
合計ジャッジ時間 7,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 131 ms
34,432 KB
testcase_05 AC 131 ms
34,472 KB
testcase_06 AC 132 ms
34,524 KB
testcase_07 AC 136 ms
34,464 KB
testcase_08 AC 132 ms
34,476 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 13 ms
4,376 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 11 ms
4,384 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 12 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 224 ms
62,744 KB
testcase_41 AC 117 ms
62,760 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();
    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