結果

問題 No.517 壊れたアクセサリー
ユーザー phsplsphspls
提出日時 2022-12-24 14:47:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,769 bytes
コンパイル時間 14,002 ms
コンパイル使用メモリ 378,608 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 04:51:42
合計ジャッジ時間 15,416 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 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 yuki = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp = temp.trim();
            temp.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 coder = (0..m).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp = temp.trim();
            temp.to_string()
        })
        .collect::<Vec<_>>();

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