結果
問題 | No.2319 Friends+ |
ユーザー | haihamabossu |
提出日時 | 2023-06-01 21:22:34 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 602 ms / 3,000 ms |
コード長 | 2,565 bytes |
コンパイル時間 | 13,993 ms |
コンパイル使用メモリ | 379,032 KB |
実行使用メモリ | 101,120 KB |
最終ジャッジ日時 | 2024-06-08 21:45:57 |
合計ジャッジ時間 | 35,775 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
99,840 KB |
testcase_01 | AC | 73 ms
99,840 KB |
testcase_02 | AC | 495 ms
100,864 KB |
testcase_03 | AC | 451 ms
100,992 KB |
testcase_04 | AC | 441 ms
100,992 KB |
testcase_05 | AC | 450 ms
100,992 KB |
testcase_06 | AC | 466 ms
100,864 KB |
testcase_07 | AC | 601 ms
100,992 KB |
testcase_08 | AC | 601 ms
100,992 KB |
testcase_09 | AC | 601 ms
100,992 KB |
testcase_10 | AC | 596 ms
101,120 KB |
testcase_11 | AC | 602 ms
100,992 KB |
testcase_12 | AC | 79 ms
99,712 KB |
testcase_13 | AC | 74 ms
99,840 KB |
testcase_14 | AC | 75 ms
99,840 KB |
testcase_15 | AC | 75 ms
99,840 KB |
testcase_16 | AC | 74 ms
99,840 KB |
testcase_17 | AC | 74 ms
99,840 KB |
testcase_18 | AC | 452 ms
100,992 KB |
testcase_19 | AC | 500 ms
100,992 KB |
testcase_20 | AC | 436 ms
100,992 KB |
testcase_21 | AC | 433 ms
101,120 KB |
testcase_22 | AC | 441 ms
100,992 KB |
testcase_23 | AC | 465 ms
100,992 KB |
testcase_24 | AC | 454 ms
100,992 KB |
testcase_25 | AC | 454 ms
101,120 KB |
testcase_26 | AC | 438 ms
100,992 KB |
testcase_27 | AC | 449 ms
100,992 KB |
testcase_28 | AC | 442 ms
100,992 KB |
testcase_29 | AC | 435 ms
100,992 KB |
testcase_30 | AC | 443 ms
100,992 KB |
testcase_31 | AC | 436 ms
100,864 KB |
testcase_32 | AC | 440 ms
100,992 KB |
testcase_33 | AC | 462 ms
100,864 KB |
testcase_34 | AC | 449 ms
100,992 KB |
testcase_35 | AC | 435 ms
100,864 KB |
testcase_36 | AC | 484 ms
100,992 KB |
testcase_37 | AC | 389 ms
100,992 KB |
testcase_38 | AC | 449 ms
100,992 KB |
testcase_39 | AC | 417 ms
100,992 KB |
testcase_40 | AC | 428 ms
100,992 KB |
testcase_41 | AC | 426 ms
100,992 KB |
testcase_42 | AC | 423 ms
100,992 KB |
testcase_43 | AC | 421 ms
100,992 KB |
testcase_44 | AC | 416 ms
100,992 KB |
testcase_45 | AC | 410 ms
100,992 KB |
testcase_46 | AC | 394 ms
101,120 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]; } }