結果

問題 No.517 壊れたアクセサリー
コンテスト
ユーザー phspls
提出日時 2022-12-03 17:00:50
言語 Rust
(1.97.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 0 ms / 2,000 ms
+ 762µs
コード長 1,701 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,501 ms
コンパイル使用メモリ 182,956 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-13 09:51:43
合計ジャッジ時間 3,136 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

    let limit = a.iter().map(|c| c.len()).sum::<usize>();
    for i in 0..n {
        let mut yuki = a[i].clone().to_owned();
        let mut coder = String::new();
        while yuki.len() < limit || coder.len() < limit {
            if yuki.len() == coder.len() {
                break;
            } else if yuki.len() < coder.len() {
                if let Some(idx) = (0..n).filter(|&j| a[j].starts_with(coder.chars().nth(yuki.len()).unwrap())).nth(0) {
                    yuki.push_str(&a[idx]);
                } else {
                    break;
                }
            } else {
                if let Some(idx) = (0..m).filter(|&j| b[j].starts_with(yuki.chars().nth(coder.len()).unwrap())).nth(0) {
                    coder.push_str(&b[idx]);
                } else {
                    break;
                }
            }
        }
        if yuki.len() == coder.len() && yuki.len() == limit {
            println!("{}", yuki);
            return;
        }
    }
    println!("-1");
}
0