結果
問題 | No.2319 Friends+ |
ユーザー | haihamabossu |
提出日時 | 2023-06-01 21:22:34 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 550 ms / 3,000 ms |
コード長 | 2,565 bytes |
コンパイル時間 | 2,972 ms |
コンパイル使用メモリ | 153,904 KB |
実行使用メモリ | 100,996 KB |
最終ジャッジ日時 | 2023-08-28 02:10:30 |
合計ジャッジ時間 | 27,113 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
99,880 KB |
testcase_01 | AC | 35 ms
99,796 KB |
testcase_02 | AC | 448 ms
100,944 KB |
testcase_03 | AC | 418 ms
100,984 KB |
testcase_04 | AC | 420 ms
100,968 KB |
testcase_05 | AC | 404 ms
100,916 KB |
testcase_06 | AC | 414 ms
100,956 KB |
testcase_07 | AC | 549 ms
100,988 KB |
testcase_08 | AC | 543 ms
100,972 KB |
testcase_09 | AC | 549 ms
100,900 KB |
testcase_10 | AC | 550 ms
100,980 KB |
testcase_11 | AC | 547 ms
100,968 KB |
testcase_12 | AC | 29 ms
99,880 KB |
testcase_13 | AC | 30 ms
99,892 KB |
testcase_14 | AC | 30 ms
99,896 KB |
testcase_15 | AC | 30 ms
99,872 KB |
testcase_16 | AC | 30 ms
99,824 KB |
testcase_17 | AC | 28 ms
99,880 KB |
testcase_18 | AC | 438 ms
100,896 KB |
testcase_19 | AC | 454 ms
100,988 KB |
testcase_20 | AC | 414 ms
100,944 KB |
testcase_21 | AC | 413 ms
100,944 KB |
testcase_22 | AC | 415 ms
100,904 KB |
testcase_23 | AC | 438 ms
100,964 KB |
testcase_24 | AC | 441 ms
100,932 KB |
testcase_25 | AC | 438 ms
100,972 KB |
testcase_26 | AC | 421 ms
100,920 KB |
testcase_27 | AC | 420 ms
100,952 KB |
testcase_28 | AC | 420 ms
100,932 KB |
testcase_29 | AC | 417 ms
100,936 KB |
testcase_30 | AC | 414 ms
100,904 KB |
testcase_31 | AC | 416 ms
100,932 KB |
testcase_32 | AC | 413 ms
100,860 KB |
testcase_33 | AC | 409 ms
100,912 KB |
testcase_34 | AC | 410 ms
100,892 KB |
testcase_35 | AC | 405 ms
100,916 KB |
testcase_36 | AC | 436 ms
100,940 KB |
testcase_37 | AC | 362 ms
100,984 KB |
testcase_38 | AC | 387 ms
100,996 KB |
testcase_39 | AC | 394 ms
100,988 KB |
testcase_40 | AC | 395 ms
100,956 KB |
testcase_41 | AC | 399 ms
100,988 KB |
testcase_42 | AC | 395 ms
100,992 KB |
testcase_43 | AC | 393 ms
100,992 KB |
testcase_44 | AC | 391 ms
100,992 KB |
testcase_45 | AC | 382 ms
100,988 KB |
testcase_46 | AC | 366 ms
100,948 KB |
ソースコード
pub mod scanner { pub struct Scanner { buf: Vec<String>, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next<T: std::str::FromStr>(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec<String> { source .split_whitespace() .rev() .map(String::from) .collect::<Vec<_>>() } } } use crate::scanner::Scanner; #[derive(Clone, Copy)] struct BitSet([u64; 313]); impl BitSet { fn new() -> Self { Self([0; 313]) } fn set(&mut self, index: usize, b: bool) { let i = index / 64; let j = index % 64; let mask = 1u64 << j; if b { self.0[i] |= mask; } else { self.0[i] &= !mask; } } fn disjoint(&self, rhs: &Self) -> bool { for i in 0..313 { if (self.0[i] & rhs.0[i]).count_ones() > 0 { return false; } } true } } fn main() { let mut scanner = Scanner::new(); let t: usize = 1; for _ in 0..t { solve(&mut scanner); } } fn solve(scanner: &mut Scanner) { let n: usize = scanner.next(); let m: usize = scanner.next(); let mut p = vec![!0; 20000]; let mut w = vec![BitSet::new(); 20000]; let mut f = vec![BitSet::new(); 20000]; for i in 0..n { let x = scanner.next::<usize>() - 1; p[i] = x; w[x].set(i, true); } for _ in 0..m { let a = scanner.next::<usize>() - 1; let b = scanner.next::<usize>() - 1; f[a].set(b, true); f[b].set(a, true); } let q: usize = scanner.next(); for _ in 0..q { let x = scanner.next::<usize>() - 1; let y = scanner.next::<usize>() - 1; if p[x] == p[y] || w[p[y]].disjoint(&f[x]) { println!("No"); continue; } println!("Yes"); w[p[x]].set(x, false); w[p[y]].set(x, true); p[x] = p[y]; } }