結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | koba-e964 |
提出日時 | 2021-08-17 15:43:50 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,436 bytes |
コンパイル時間 | 14,179 ms |
コンパイル使用メモリ | 376,864 KB |
実行使用メモリ | 37,504 KB |
最終ジャッジ日時 | 2024-10-10 13:20:25 |
合計ジャッジ時間 | 20,748 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | WA | - |
testcase_08 | AC | 77 ms
33,664 KB |
testcase_09 | AC | 73 ms
29,696 KB |
testcase_10 | AC | 74 ms
33,920 KB |
testcase_11 | AC | 63 ms
23,936 KB |
testcase_12 | AC | 68 ms
22,528 KB |
testcase_13 | AC | 72 ms
25,216 KB |
testcase_14 | AC | 78 ms
34,688 KB |
testcase_15 | AC | 85 ms
34,304 KB |
testcase_16 | AC | 70 ms
32,128 KB |
testcase_17 | AC | 70 ms
25,856 KB |
testcase_18 | AC | 56 ms
23,936 KB |
testcase_19 | AC | 75 ms
34,304 KB |
testcase_20 | AC | 66 ms
30,592 KB |
testcase_21 | AC | 76 ms
35,584 KB |
testcase_22 | AC | 76 ms
35,328 KB |
testcase_23 | AC | 70 ms
35,712 KB |
testcase_24 | AC | 70 ms
31,232 KB |
testcase_25 | AC | 74 ms
32,640 KB |
testcase_26 | AC | 80 ms
35,840 KB |
testcase_27 | AC | 78 ms
36,096 KB |
testcase_28 | AC | 78 ms
37,248 KB |
testcase_29 | AC | 77 ms
37,376 KB |
testcase_30 | AC | 73 ms
34,048 KB |
testcase_31 | AC | 80 ms
37,504 KB |
testcase_32 | AC | 79 ms
36,736 KB |
testcase_33 | AC | 71 ms
31,744 KB |
testcase_34 | AC | 82 ms
37,376 KB |
testcase_35 | AC | 73 ms
32,512 KB |
testcase_36 | AC | 81 ms
37,248 KB |
testcase_37 | AC | 79 ms
37,248 KB |
testcase_38 | AC | 81 ms
28,800 KB |
testcase_39 | AC | 70 ms
24,704 KB |
testcase_40 | AC | 66 ms
28,288 KB |
testcase_41 | AC | 68 ms
24,832 KB |
testcase_42 | AC | 66 ms
28,416 KB |
testcase_43 | AC | 1 ms
5,248 KB |
testcase_44 | AC | 3 ms
6,528 KB |
testcase_45 | AC | 55 ms
18,276 KB |
testcase_46 | AC | 71 ms
18,284 KB |
testcase_47 | AC | 53 ms
18,312 KB |
testcase_48 | AC | 61 ms
18,368 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => (read_value!($next, usize) - 1); ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); read_value!($next, [$t; len]) }}; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); } fn dfs(v: usize, par: usize, vis: &mut [bool], g: &[Vec<(usize, usize)>], ) -> Result<(), (bool, usize, Vec<usize>)> { if vis[v] { return Err((true, v, vec![])); } vis[v] = true; for &(w, idx) in &g[v] { if w == par { continue; } let sub = dfs(w, v, vis, g); if let Err((extending, orig, mut sub)) = sub { if extending { sub.push(idx + 1); } return Err((extending && orig != v, orig, sub)); } } Ok(()) } fn solve() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} #[allow(unused)] macro_rules! putvec { ($v:expr) => { for i in 0..$v.len() { puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "}); } } } input! { h: usize, w: usize, n: usize, xy: [(usize1, usize1); n], } let mut g = vec![vec![]; h + w]; for i in 0..n { let (x, y) = xy[i]; g[x].push((h + y, i)); g[h + y].push((x, i)); } let mut vis = vec![false; h + w]; for i in 0..h { if vis[i] { continue; } let res = dfs(i, h + w, &mut vis, &g); if let Err((_, _, mut path)) = res { path.reverse(); puts!("{}\n", path.len()); putvec!(path); return; } } puts!("-1\n"); }