結果
問題 | No.517 壊れたアクセサリー |
ユーザー | gyu-don |
提出日時 | 2017-07-27 20:33:05 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 2,822 bytes |
コンパイル時間 | 13,074 ms |
コンパイル使用メモリ | 378,792 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 02:13:17 |
合計ジャッジ時間 | 14,235 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 1 ms
5,248 KB |
testcase_15 | AC | 1 ms
5,248 KB |
testcase_16 | AC | 1 ms
5,248 KB |
testcase_17 | AC | 1 ms
5,248 KB |
testcase_18 | AC | 1 ms
5,248 KB |
コンパイルメッセージ
warning: unused import: `std::io::prelude` --> src/main.rs:1:5 | 1 | use std::io::prelude::*; | ^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused variable: `i` --> src/main.rs:26:9 | 26 | for i in 0..n { | ^ help: if this is intentional, prefix it with an underscore: `_i` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `i` --> src/main.rs:54:9 | 54 | for i in 0..n { | ^ help: if this is intentional, prefix it with an underscore: `_i`
ソースコード
use std::io::prelude::*; use std::io::stdin; use std::fmt::Debug; use std::str; #[derive(Debug, Clone)] struct List { pub prev: Option<usize>, pub next: Option<usize>, pub used: bool, } fn main() { let mut list: Vec<List> = vec![List { prev: None, next: None, used: false }; 26]; let n: usize = { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); s.trim().parse().unwrap() }; if n == 1 { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); println!("{}", s.trim()); return; } for i in 0..n { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); if s.trim().len() == 1 { let i = (s.as_bytes()[0] - 'A' as u8) as usize; list[i].used = true; } for b in s.trim().as_bytes().windows(2) { let i = (b[0] - 'A' as u8) as usize; let j = (b[1] - 'A' as u8) as usize; list[i].next = Some(j); list[j].prev = Some(i); list[i].used = true; list[j].used = true; } } let n: usize = { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); s.trim().parse().unwrap() }; if n == 1 { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); println!("{}", s.trim()); return; } for i in 0..n { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); if s.trim().len() == 1 { let i = (s.as_bytes()[0] - 'A' as u8) as usize; list[i].used = true; } for b in s.trim().as_bytes().windows(2) { let i = (b[0] - 'A' as u8) as usize; let j = (b[1] - 'A' as u8) as usize; list[i].next = Some(j); list[j].prev = Some(i); list[i].used = true; list[j].used = true; } } let mut cursor = None; let mut s = vec![]; let mut count = 0; for (i,c) in list.iter().enumerate() { if c.prev.is_none() && c.next.is_some() { if cursor.is_some() { println!("-1"); return; } cursor = c.next.clone(); s.push(i as u8 + 'A' as u8); } if c.used { count += 1; //println!("{}: {:?}", (i as u8 + 'A' as u8) as char, c); } } if cursor.is_none() { println!("-1"); return; } else { while cursor.is_some() { let n = *cursor.as_ref().unwrap(); s.push(n as u8 + 'A' as u8); cursor = list[n].next; } } if s.len() != count { println!("-1"); } else { println!("{}", str::from_utf8(&s).unwrap()); } }