結果

問題 No.517 壊れたアクセサリー
ユーザー phsplsphspls
提出日時 2022-12-03 17:00:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,701 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 159,352 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 02:49:56
合計ジャッジ時間 1,769 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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