-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathapg4b-ex25.rs
56 lines (45 loc) · 1.36 KB
/
apg4b-ex25.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// https://atcoder.jp/contests/APG4b/tasks/APG4b_bx
use fixedbitset::FixedBitSet;
use itertools::Itertools as _;
use proconio::input;
#[allow(clippy::many_single_char_names)]
fn main() {
input! {
a: [usize],
b: [usize],
arg0: String,
args: [usize; if arg0 == "subtract" { 1 } else { 0 }],
}
let (a, b) = (a.into_iter().collect(), b.into_iter().collect());
print_set(&match (&*arg0, &*args) {
("intersection", []) => intersection(&a, &b),
("union_set", []) => union_set(&a, &b),
("symmetric_diff", []) => symmetric_diff(&a, &b),
("subtract", &[x]) => subtract(a, x),
("increment", []) => increment(&a),
("decrement", []) => decrement(&a),
_ => unreachable!(),
});
}
fn print_set(set: &FixedBitSet) {
println!("{}", (0..50).filter(|&i| set[i]).format(" "));
}
fn intersection(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
a & b
}
fn union_set(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
a | b
}
fn symmetric_diff(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
a ^ b
}
fn subtract(mut a: FixedBitSet, x: usize) -> FixedBitSet {
a.set(x, false);
a
}
fn increment(a: &FixedBitSet) -> FixedBitSet {
a.ones().map(|x| (x + 1) % 50).collect()
}
fn decrement(a: &FixedBitSet) -> FixedBitSet {
a.ones().map(|x| (x + 49) % 50).collect()
}