結果
問題 |
No.517 壊れたアクセサリー
|
ユーザー |
|
提出日時 | 2022-12-24 14:47:42 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,769 bytes |
コンパイル時間 | 14,464 ms |
コンパイル使用メモリ | 378,244 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-18 05:12:47 |
合計ジャッジ時間 | 11,609 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
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"); }