結果
問題 | No.2977 Kth Xor Pair |
ユーザー | titia |
提出日時 | 2024-12-15 05:00:50 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,543 bytes |
コンパイル時間 | 15,336 ms |
コンパイル使用メモリ | 378,576 KB |
実行使用メモリ | 88,992 KB |
最終ジャッジ日時 | 2024-12-15 05:02:09 |
合計ジャッジ時間 | 58,083 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 5 ms
5,248 KB |
testcase_03 | AC | 5 ms
5,248 KB |
testcase_04 | AC | 5 ms
5,248 KB |
testcase_05 | AC | 5 ms
5,248 KB |
testcase_06 | AC | 5 ms
5,248 KB |
testcase_07 | AC | 947 ms
47,776 KB |
testcase_08 | AC | 2,163 ms
80,416 KB |
testcase_09 | AC | 1,828 ms
72,372 KB |
testcase_10 | AC | 1,910 ms
73,564 KB |
testcase_11 | AC | 2,159 ms
75,304 KB |
testcase_12 | AC | 2,197 ms
73,704 KB |
testcase_13 | AC | 2,372 ms
84,608 KB |
testcase_14 | WA | - |
testcase_15 | AC | 1,803 ms
68,648 KB |
testcase_16 | AC | 2,396 ms
83,876 KB |
testcase_17 | AC | 2,425 ms
81,380 KB |
testcase_18 | AC | 2,274 ms
86,936 KB |
testcase_19 | AC | 2,278 ms
88,992 KB |
testcase_20 | AC | 2,412 ms
86,340 KB |
testcase_21 | AC | 2,304 ms
83,452 KB |
testcase_22 | AC | 2,588 ms
87,284 KB |
testcase_23 | AC | 2,453 ms
81,132 KB |
testcase_24 | AC | 2,548 ms
81,928 KB |
testcase_25 | WA | - |
testcase_26 | AC | 2,564 ms
85,240 KB |
testcase_27 | AC | 830 ms
9,756 KB |
testcase_28 | AC | 400 ms
9,756 KB |
testcase_29 | AC | 527 ms
9,756 KB |
testcase_30 | AC | 711 ms
9,880 KB |
testcase_31 | AC | 633 ms
9,880 KB |
testcase_32 | AC | 444 ms
6,272 KB |
testcase_33 | AC | 394 ms
6,272 KB |
testcase_34 | AC | 410 ms
6,272 KB |
testcase_35 | AC | 432 ms
6,272 KB |
ソースコード
use std::io; fn main() { let mut input = String::new(); io::stdin().read_line(&mut input).unwrap(); let mut iter = input.trim().split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let k: usize = iter.next().unwrap().parse().unwrap(); input.clear(); io::stdin().read_line(&mut input).unwrap(); let a: Vec<i32> = input .trim() .split_whitespace() .map(|x| x.parse().unwrap()) .collect(); let r = n * (n - 1) / 2 - k + 1; let mut next_node_id0 = vec![-1]; let mut next_node_id1 = vec![-1]; let mut parent_id = vec![-1]; let mut depth = vec![0]; let mut count = vec![0]; let mut last = Vec::new(); let mut nodes_id = 1; for &num in &a { let mut now = 0; for i in (0..=31).rev() { let next = if num & (1 << i) == 0 { 0 } else { 1 }; if next == 0 { if next_node_id0[now] == -1 { next_node_id0[now] = nodes_id as i32; next_node_id0.push(-1); next_node_id1.push(-1); parent_id.push(now as i32); depth.push(depth[now] + 1); count.push(0); now = nodes_id; nodes_id += 1; } else { now = next_node_id0[now] as usize; } } else { if next_node_id1[now] == -1 { next_node_id1[now] = nodes_id as i32; next_node_id0.push(-1); next_node_id1.push(-1); parent_id.push(now as i32); depth.push(depth[now] + 1); count.push(0); now = nodes_id; nodes_id += 1; } else { now = next_node_id1[now] as usize; } } } count[now] += 1; last.push(now); } let mut count2 = vec![0; count.len()]; for &x in &last { let mut node = x as i32; while node != -1 { count2[node as usize] += 1; node = parent_id[node as usize]; } } let mut ok = 0; let mut ng = *a.iter().max().unwrap() + 1; while ng > ok + 1 { let mid = (ok + ng) / 2; let mut total_count = 0; for &num in &a { if total_count / 2 >= r { break; } let mut now = 0; let mut current_count = 0; let mut flag = false; for dep in (0..=31).rev() { let x = next_node_id0[now]; let y = next_node_id1[now]; let num_bit = num & (1 << dep); let mid_bit = mid & (1 << dep); match (num_bit == 0, mid_bit == 0) { (true, true) => { if y != -1 { current_count += count2[y as usize]; } if x != -1 { now = x as usize; } else { flag = true; break; } } (true, false) => { if y != -1 { now = y as usize; } else { flag = true; break; } } (false, true) => { if x != -1 { current_count += count2[x as usize]; } if y != -1 { now = y as usize; } else { flag = true; break; } } (false, false) => { if x != -1 { now = x as usize; } else { flag = true; break; } } } } if !flag { current_count += count2[now]; } total_count += current_count; } if total_count / 2 >= r { ok = mid; } else { ng = mid; } } println!("{}", ok); }