結果

問題 No.962 LCPs
ユーザー tonyu0tonyu0
提出日時 2019-12-25 22:35:08
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,851 bytes
コンパイル時間 7,505 ms
コンパイル使用メモリ 162,912 KB
実行使用メモリ 13,212 KB
最終ジャッジ日時 2024-04-08 16:12:55
合計ジャッジ時間 10,248 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 19 ms
13,212 KB
testcase_18 AC 11 ms
7,552 KB
testcase_19 AC 11 ms
7,552 KB
testcase_20 AC 8 ms
6,676 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 7 ms
6,676 KB
testcase_24 AC 7 ms
6,676 KB
testcase_25 AC 7 ms
6,676 KB
testcase_26 AC 6 ms
6,676 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 2 ms
6,676 KB
testcase_48 AC 2 ms
6,676 KB
testcase_49 AC 2 ms
6,676 KB
testcase_50 AC 2 ms
6,676 KB
testcase_51 AC 3 ms
6,676 KB
testcase_52 WA -
testcase_53 AC 2 ms
6,676 KB
testcase_54 AC 2 ms
6,676 KB
testcase_55 AC 1 ms
6,676 KB
testcase_56 AC 3 ms
6,676 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 3 ms
6,676 KB
testcase_61 AC 2 ms
6,676 KB
testcase_62 AC 2 ms
6,676 KB
testcase_63 WA -
testcase_64 AC 2 ms
6,676 KB
testcase_65 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<Vec<char>> = (0..n)
        .map(|_| itr.next().unwrap().chars().collect())
        .collect();

    let mut ans: u64 = 0;
    let mut stack: Vec<(u64, u64)> = Vec::new();
    for i in 0..n {
        ans += s[i].len() as u64;
        if i == n - 1 {
            while let Some((cnt, pos)) = stack.pop() {
                let mut a: u64 = i as u64 - pos + 1;
                let mut b: u64 = 1;
                while a > 1 {
                    ans += cnt * a * b;
                    a -= 1;
                    b += 1;
                }
            }
            break;
        }
        let mut m: u64 = 0;
        let k = std::cmp::min(s[i].len(), s[i + 1].len());
        for j in 0..k {
            if s[i][j] != s[i + 1][j] {
                break;
            }
            m += 1;
        }
        if m > 0 {
            // 今よりマッチ数が小さくなるまでpop
            let mut need: bool = true;
            while let Some((cnt, pos)) = stack.pop() {
                if cnt == m {
                    need = false;
                    stack.push((cnt, pos));
                    break;
                } else if cnt < m {
                    stack.push((cnt, pos));
                    break;
                }
                let mut a: u64 = i as u64 - pos + 1;
                let mut b: u64 = 1;
                while a > 1 {
                    ans += (cnt - m) * a * b;
                    a -= 1;
                    b += 1;
                }
            }
            if need {
                stack.push((m, i as u64));
            }
        }
    }
    println!("{}", ans);
}
0