結果
問題 | No.483 マッチ並べ |
ユーザー | mio_h |
提出日時 | 2017-02-12 22:52:17 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 3,870 bytes |
コンパイル時間 | 13,793 ms |
コンパイル使用メモリ | 398,292 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-09 10:08:56 |
合計ジャッジ時間 | 15,252 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 0 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 0 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,944 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 1 ms
6,944 KB |
testcase_16 | AC | 0 ms
6,944 KB |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,944 KB |
testcase_20 | AC | 1 ms
6,940 KB |
testcase_21 | AC | 1 ms
6,944 KB |
testcase_22 | AC | 1 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 1 ms
6,940 KB |
testcase_25 | AC | 1 ms
6,940 KB |
testcase_26 | AC | 1 ms
6,940 KB |
testcase_27 | AC | 1 ms
6,940 KB |
testcase_28 | AC | 1 ms
6,940 KB |
testcase_29 | AC | 1 ms
6,940 KB |
testcase_30 | AC | 1 ms
6,944 KB |
testcase_31 | AC | 1 ms
6,940 KB |
testcase_32 | AC | 1 ms
6,944 KB |
testcase_33 | AC | 1 ms
6,944 KB |
testcase_34 | AC | 1 ms
6,940 KB |
testcase_35 | AC | 1 ms
6,940 KB |
testcase_36 | AC | 1 ms
6,944 KB |
testcase_37 | AC | 1 ms
6,944 KB |
testcase_38 | AC | 1 ms
6,944 KB |
testcase_39 | AC | 1 ms
6,944 KB |
testcase_40 | AC | 1 ms
6,940 KB |
testcase_41 | AC | 1 ms
6,940 KB |
testcase_42 | AC | 1 ms
6,940 KB |
testcase_43 | AC | 1 ms
6,940 KB |
testcase_44 | AC | 1 ms
6,944 KB |
testcase_45 | AC | 1 ms
6,940 KB |
testcase_46 | AC | 1 ms
6,944 KB |
testcase_47 | AC | 1 ms
6,944 KB |
testcase_48 | AC | 1 ms
6,944 KB |
testcase_49 | AC | 1 ms
6,944 KB |
testcase_50 | AC | 1 ms
6,940 KB |
testcase_51 | AC | 1 ms
6,940 KB |
testcase_52 | AC | 1 ms
6,944 KB |
testcase_53 | AC | 1 ms
6,944 KB |
testcase_54 | AC | 1 ms
6,940 KB |
testcase_55 | AC | 1 ms
6,940 KB |
コンパイルメッセージ
warning: use of deprecated method `std::error::Error::description`: use the Display impl or to_string() --> src/main.rs:112:62 | 112 | Err(why) => panic!("error in read_line: {}", why.description()), | ^^^^^^^^^^^ | = note: `#[warn(deprecated)]` on by default
ソースコード
use std::io::{self, Stdin}; use std::str::{self, FromStr}; use std::error::Error; use std::thread; use std::collections::*; fn exec() { let mut sc = Scanner::new(); let n: usize = sc.ne(); let mut edge = vec![(0, 0); n]; let mut num = BTreeMap::new(); for i in 0..n { let y1 = sc.ne::<usize>() - 1; let x1 = sc.ne::<usize>() - 1; let y2 = sc.ne::<usize>() - 1; let x2 = sc.ne::<usize>() - 1; let n1 = y1 * 100 + x1; let n2 = y2 * 100 + x2; edge[i] = (n1, n2); num.insert(n1, 0); num.insert(n2, 0); } let m = num.len(); let mut t = 0; for (_, val) in num.iter_mut() { *val = t; t += 1; } let mut adj = vec![Vec::new(); n + m]; for i in 0..n { let u = num[&edge[i].0]; let v = num[&edge[i].1]; adj[i].push(n + u); adj[i].push(n + v); adj[n + u].push(i); adj[n + v].push(i); } let ans = match bimatch(&adj, n) { val if val == n => "YES", _ => "NO", }; println!("{}", ans); } fn bimatch(adj: &Vec<Vec<usize>>, ln: usize) -> usize { fn dfs(cur: usize, adj: &Vec<Vec<usize>>, mut match_to: &mut Vec<Option<usize>>, mut used: &mut Vec<bool>) -> bool { for &nxt in &adj[cur] { if used[nxt] { continue; } used[nxt] = true; let assign = match match_to[nxt] { Some(v) => dfs(v, &adj, &mut match_to, &mut used), None => true, }; if assign { match_to[cur] = Some(nxt); match_to[nxt] = Some(cur); return true; } } false } let n = adj.len(); let mut match_to: Vec<Option<usize>> = vec![None; n]; let mut res = 0; for i in 0..ln { if match_to[i] != None { continue; } let mut used = vec![false; n]; if dfs(i, &adj, &mut match_to, &mut used) { res += 1; } } res } fn main() { const DEFAULT_STACK: usize = 16 * 1024 * 1024; let builder = thread::Builder::new(); let th = builder.stack_size(DEFAULT_STACK); let handle = th.spawn(|| { exec(); }).unwrap(); let _ = handle.join(); } #[allow(dead_code)] struct Scanner { stdin: Stdin, id: usize, buf: Vec<u8>, } #[allow(dead_code)] impl Scanner { fn new() -> Scanner { Scanner { stdin: io::stdin(), id: 0, buf: Vec::new(), } } fn next_line(&mut self) -> Option<String> { let mut res = String::new(); match self.stdin.read_line(&mut res) { Ok(0) => return None, Ok(_) => Some(res), Err(why) => panic!("error in read_line: {}", why.description()), } } fn next<T: FromStr>(&mut self) -> Option<T> { while self.buf.len() == 0 { self.buf = match self.next_line() { Some(r) => { self.id = 0; r.trim().as_bytes().to_owned() } None => return None, }; } let l = self.id; assert!(self.buf[l] != b' '); let n = self.buf.len(); let mut r = l; while r < n && self.buf[r] != b' ' { r += 1; } let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() { Ok(s) => Some(s), Err(_) => panic!("parse error"), }; while r < n && self.buf[r] == b' ' { r += 1; } if r == n { self.buf.clear(); } else { self.id = r; } res } fn ne<T: FromStr>(&mut self) -> T { self.next::<T>().unwrap() } }