結果
問題 | No.2274 三角彩色 |
ユーザー | akakimidori |
提出日時 | 2023-04-14 22:58:16 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,350 bytes |
コンパイル時間 | 12,448 ms |
コンパイル使用メモリ | 388,452 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-10 13:59:26 |
合計ジャッジ時間 | 13,920 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 0 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:3:9 | 3 | n: usize, | ^ | help: `n` is captured in macro and introduced a unused variable --> src/main.rs:74:13 | 2 | / input! { 3 | | n: usize, 4 | | m: usize, 5 | | modulo: u64, ... | 8 | | a: [(usize, usize, usize); q], 9 | | } | |_____- in this macro invocation ... 74 | let $var = read_value!($iter, $t); | ^^^^ = note: `#[warn(unused_variables)]` on by default = note: this warning originates in the macro `input_inner` which comes from the expansion of the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info)
ソースコード
fn main() { input! { n: usize, m: usize, modulo: u64, q: usize, e: [(usize, usize); m], a: [(usize, usize, usize); q], } let mut z = e.iter().flat_map(|e| [e.0, e.1]).collect::<Vec<_>>(); z.sort(); z.dedup(); let mut e = e; for e in e.iter_mut() { e.0 = z.binary_search(&e.0).unwrap(); e.1 = z.binary_search(&e.1).unwrap(); } let mut dsu = DSU::new(z.len()); let mut all = 1 % modulo; for &(a, b) in e.iter() { if dsu.unite(a, b).is_some() { all = 2 * all % modulo; } } let all = all; let mut base: Vec<Vec<u8>> = vec![]; let mut t = 1; for a in a.iter() { let mut b = vec![0u8; m]; b[a.0] = 1; b[a.1] = 1; b[a.2] = 1; for x in base.iter() { let pos = x.iter().position(|x| *x == 1).unwrap(); if b[pos] == 1 { for (b, x) in b.iter_mut().zip(x.iter()) { *b ^= *x; } } } if b.iter().any(|b| *b > 0) { base.push(b); t = 2 * t % modulo; } } println!("{} {}", (all + modulo - t) % modulo, t); } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- //---------- begin union_find ---------- pub struct DSU { p: Vec<i32>, } impl DSU { pub fn new(n: usize) -> DSU { assert!(n < std::i32::MAX as usize); DSU { p: vec![-1; n] } } pub fn init(&mut self) { self.p.iter_mut().for_each(|p| *p = -1); } pub fn root(&self, mut x: usize) -> usize { assert!(x < self.p.len()); while self.p[x] >= 0 { x = self.p[x] as usize; } x } pub fn same(&self, x: usize, y: usize) -> bool { assert!(x < self.p.len() && y < self.p.len()); self.root(x) == self.root(y) } pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> { assert!(x < self.p.len() && y < self.p.len()); let mut x = self.root(x); let mut y = self.root(y); if x == y { return None; } if self.p[x] > self.p[y] { std::mem::swap(&mut x, &mut y); } self.p[x] += self.p[y]; self.p[y] = x as i32; Some((x, y)) } pub fn parent(&self, x: usize) -> Option<usize> { assert!(x < self.p.len()); let p = self.p[x]; if p >= 0 { Some(p as usize) } else { None } } pub fn sum<F>(&self, mut x: usize, mut f: F) -> usize where F: FnMut(usize), { while let Some(p) = self.parent(x) { f(x); x = p; } x } pub fn size(&self, x: usize) -> usize { assert!(x < self.p.len()); let r = self.root(x); (-self.p[r]) as usize } } //---------- end union_find ----------