Skip to content

Commit 9b3b5e9

Browse files
committed
Add a test for APG4b-EX25
1 parent 85378b7 commit 9b3b5e9

14 files changed

+129
-0
lines changed

examples/apg4b-ex25.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// https://atcoder.jp/contests/APG4b/tasks/APG4b_bx
2+
3+
use fixedbitset::FixedBitSet;
4+
use itertools::Itertools as _;
5+
6+
fn main() {
7+
// use std::io::{self, Read as _};
8+
//
9+
// let mut input = "".to_owned();
10+
// io::stdin().read_to_string(&mut input).unwrap();
11+
// let mut input = input.split_whitespace();
12+
// macro_rules! read {
13+
// ([$t:tt; $n:expr]) => {
14+
// (0..$n).map(|_| read!($t)).collect::<Vec<_>>()
15+
// };
16+
// (($($t:tt),+)) => {
17+
// ($(read!($t)),*)
18+
// };
19+
// (_1based) => {
20+
// read!(usize) - 1
21+
// };
22+
// (_bytes) => {
23+
// read!(String).into_bytes()
24+
// };
25+
// ($ty:ty) => {
26+
// input.next().unwrap().parse::<$ty>().unwrap()
27+
// };
28+
// }
29+
//
30+
// let n = read!(usize);
31+
// let a = read!([usize; n]);
32+
// let m = read!(usize);
33+
// let b = read!([usize; m]);
34+
// let arg0 = read!(String);
35+
// let args = read!([usize; if arg0 == "subtract" { 1 } else { 0 }]);
36+
37+
use proconio::input;
38+
39+
input! {
40+
n: usize,
41+
a: [usize; n],
42+
m: usize,
43+
b: [usize; m],
44+
arg0: String,
45+
args: [usize; if arg0 == "subtract" { 1 } else { 0 }],
46+
}
47+
48+
let (a, b) = (a.into_iter().collect(), b.into_iter().collect());
49+
50+
print_set(&match (&*arg0, &*args) {
51+
("intersection", []) => intersection(&a, &b),
52+
("union_set", []) => union_set(&a, &b),
53+
("symmetric_diff", []) => symmetric_diff(&a, &b),
54+
("subtract", &[x]) => subtract(a, x),
55+
("increment", []) => increment(&a),
56+
("decrement", []) => decrement(&a),
57+
_ => unreachable!(),
58+
});
59+
}
60+
61+
fn print_set(set: &FixedBitSet) {
62+
println!("{}", (0..50).filter(|&i| set[i]).format(" "));
63+
}
64+
65+
fn intersection(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
66+
a & b
67+
}
68+
69+
fn union_set(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
70+
a | b
71+
}
72+
73+
fn symmetric_diff(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
74+
a ^ b
75+
}
76+
77+
fn subtract(mut a: FixedBitSet, x: usize) -> FixedBitSet {
78+
// > xは存在することが保証される。
79+
a.set(x, false);
80+
a
81+
}
82+
83+
fn increment(a: &FixedBitSet) -> FixedBitSet {
84+
a.ones().map(|x| (x + 1) % 50).collect()
85+
}
86+
87+
fn decrement(a: &FixedBitSet) -> FixedBitSet {
88+
a.ones().map(|x| (x + 49) % 50).collect()
89+
}

examples/tests.ron

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
name: "APG4b: A - 1.00.はじめに",
88
matching: ExactWhole,
99
),
10+
"apg4b-ex25": (
11+
name: "APG4b: EX25 - 集合の操作 / 3.05",
12+
matching: ExactWords,
13+
),
1014
"practice-a": (
1115
name: "practice contest: A - Welcome to AtCoder",
1216
matching: ExactWords,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 2
3+
3
4+
1 2 3
5+
intersection
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 2
3+
3
4+
1 2 3
5+
union_set
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 2
3+
3
4+
1 2 3
5+
symmetric_diff
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 2
3+
3
4+
1 2 3
5+
subtract 2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 49
3+
3
4+
1 2 3
5+
increment
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 49
3+
3
4+
1 2 3
5+
decrement
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 1 2 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 1 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 48 49

0 commit comments

Comments
 (0)