結果
問題 | No.1290 Addition and Subtraction Operation |
ユーザー | koba-e964 |
提出日時 | 2021-11-18 23:54:10 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 3,601 bytes |
コンパイル時間 | 21,745 ms |
コンパイル使用メモリ | 378,132 KB |
実行使用メモリ | 6,656 KB |
最終ジャッジ日時 | 2024-12-12 11:54:18 |
合計ジャッジ時間 | 21,246 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 2 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 | 2 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 | 2 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 |
testcase_19 | AC | 1 ms
5,248 KB |
testcase_20 | AC | 1 ms
5,248 KB |
testcase_21 | AC | 1 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 1 ms
5,248 KB |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 1 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 1 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 1 ms
5,248 KB |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 1 ms
5,248 KB |
testcase_35 | AC | 1 ms
5,248 KB |
testcase_36 | AC | 1 ms
5,248 KB |
testcase_37 | AC | 1 ms
5,248 KB |
testcase_38 | AC | 1 ms
5,248 KB |
testcase_39 | AC | 1 ms
5,248 KB |
testcase_40 | AC | 1 ms
5,248 KB |
testcase_41 | AC | 1 ms
5,248 KB |
testcase_42 | AC | 14 ms
5,248 KB |
testcase_43 | AC | 14 ms
5,248 KB |
testcase_44 | AC | 14 ms
5,248 KB |
testcase_45 | AC | 14 ms
5,248 KB |
testcase_46 | AC | 14 ms
5,248 KB |
testcase_47 | AC | 14 ms
5,248 KB |
testcase_48 | AC | 14 ms
5,248 KB |
testcase_49 | AC | 14 ms
5,248 KB |
testcase_50 | AC | 14 ms
5,248 KB |
testcase_51 | AC | 14 ms
5,248 KB |
testcase_52 | AC | 14 ms
5,248 KB |
testcase_53 | AC | 14 ms
5,248 KB |
testcase_54 | AC | 14 ms
5,248 KB |
testcase_55 | AC | 14 ms
5,248 KB |
testcase_56 | AC | 14 ms
5,248 KB |
testcase_57 | AC | 15 ms
5,840 KB |
testcase_58 | AC | 18 ms
5,840 KB |
testcase_59 | AC | 15 ms
5,716 KB |
testcase_60 | AC | 27 ms
6,400 KB |
testcase_61 | AC | 23 ms
6,016 KB |
testcase_62 | AC | 24 ms
6,144 KB |
testcase_63 | AC | 18 ms
5,836 KB |
testcase_64 | AC | 11 ms
5,888 KB |
testcase_65 | AC | 13 ms
5,840 KB |
testcase_66 | AC | 21 ms
5,888 KB |
testcase_67 | AC | 28 ms
6,656 KB |
testcase_68 | AC | 23 ms
6,144 KB |
testcase_69 | AC | 18 ms
5,796 KB |
testcase_70 | AC | 16 ms
5,840 KB |
testcase_71 | AC | 19 ms
5,840 KB |
testcase_72 | AC | 12 ms
5,840 KB |
testcase_73 | AC | 21 ms
6,016 KB |
testcase_74 | AC | 11 ms
5,760 KB |
testcase_75 | AC | 11 ms
5,760 KB |
testcase_76 | AC | 17 ms
5,844 KB |
testcase_77 | AC | 25 ms
6,144 KB |
testcase_78 | AC | 24 ms
6,016 KB |
testcase_79 | AC | 18 ms
5,836 KB |
testcase_80 | AC | 29 ms
6,400 KB |
testcase_81 | AC | 28 ms
6,400 KB |
testcase_82 | AC | 21 ms
5,836 KB |
testcase_83 | AC | 28 ms
6,400 KB |
testcase_84 | AC | 27 ms
6,400 KB |
testcase_85 | AC | 15 ms
5,844 KB |
testcase_86 | AC | 12 ms
5,888 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; // 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, [graph1; $len:expr]) => {{ let mut g = vec![vec![]; $len]; let ab = read_value!($next, [(usize1, usize1)]); for (a, b) in ab { g[a].push(b); g[b].push(a); } g }}; ($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")); } /** * Union-Find tree. * Verified by https://atcoder.jp/contests/pakencamp-2019-day3/submissions/9253305 */ struct UnionFind { disj: Vec<usize>, rank: Vec<usize> } impl UnionFind { fn new(n: usize) -> Self { let disj = (0..n).collect(); UnionFind { disj: disj, rank: vec![1; n] } } fn root(&mut self, x: usize) -> usize { if x != self.disj[x] { let par = self.disj[x]; let r = self.root(par); self.disj[x] = r; } self.disj[x] } fn unite(&mut self, x: usize, y: usize) { let mut x = self.root(x); let mut y = self.root(y); if x == y { return } if self.rank[x] > self.rank[y] { std::mem::swap(&mut x, &mut y); } self.disj[x] = y; self.rank[y] += self.rank[x]; } #[allow(unused)] fn is_same_set(&mut self, x: usize, y: usize) -> bool { self.root(x) == self.root(y) } #[allow(unused)] fn size(&mut self, x: usize) -> usize { let x = self.root(x); self.rank[x] } } fn solve() { input! { n: usize, m: usize, b: [i64; n], lr: [(usize1, usize); m], } let mut b = b; for i in 0..n { if i % 2 == 1 { b[i] = -b[i]; } } let mut c = vec![0; n + 1]; c[0] = b[0]; for i in 1..n { c[i] = b[i] - b[i - 1]; } c[n] = -b[n - 1]; let mut uf = UnionFind::new(n + 1); for (l, r) in lr { uf.unite(l, r); } let mut tot = vec![0; n + 1]; for i in 0..n + 1 { tot[uf.root(i)] += c[i]; } println!("{}", if tot.iter().all(|&x| x == 0) { "YES" } else { "NO" }); } 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(); }