結果
問題 | No.1267 Stop and Coin Game |
ユーザー | akakimidori |
提出日時 | 2020-10-24 18:36:37 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,407 bytes |
コンパイル時間 | 13,264 ms |
コンパイル使用メモリ | 394,132 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-21 15:25:14 |
合計ジャッジ時間 | 13,331 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
ソースコード
//---------- begin union_find ---------- pub struct DSU { p: Vec<i32>, } impl DSU { pub fn new(n: usize) -> DSU { DSU { p: vec![-1; n] } } pub fn init(&mut self) { for p in self.p.iter_mut() { *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()); assert!(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()); assert!(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 size(&self, x: usize) -> usize { assert!(x < self.p.len()); let r = self.root(x); (-self.p[r]) as usize } } //---------- end union_find ---------- // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 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_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_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 ---------- use std::io::Write; fn run() { input! { n: usize, m: usize, q: usize, s: [bytes; n], e: [(usize1, usize1); m], ask: [(u8, usize1, usize); q], } let mut s = s.into_iter().map(|s| { s.iter().rev().fold(0, |s, a| (s << 1) | ((*a == b'1') as usize)) }).collect::<Vec<_>>(); let f = 7; let mut g = vec![vec![]; n]; let mut dsu = DSU::new(f * n); for (v, s) in s.iter().enumerate() { for i in 0..f { let j = (i + 1) % 7; if (*s >> i) & (*s >> j) & 1 == 1 { dsu.unite(i * n + v, j * n + v); } } } for (a, b) in e { g[a].push(b); g[b].push(a); for i in 0..f { if (s[a] & s[b]) >> i & 1 == 1 { dsu.unite(i * n + a, i * n + b); } } } let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); for (op, x, y) in ask { if op == 1 { let y = y - 1; s[x] |= 1 << y; for &u in g[x].iter() { if s[u] >> y & 1 == 1 { dsu.unite(y * n + x, y * n + u); } } for i in [(y + 1) % 7, (y + 6) % 7].iter() { if s[x] >> i & 1 == 1 { dsu.unite(i * n + x, y * n + x); } } } else { let ans = dsu.size(x); writeln!(out, "{}", ans).ok(); } } } fn main() { run(); }