Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44be0d2

Browse files
committed
Add an example for AGC020-C
1 parent 97f555d commit 44be0d2

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

examples/agc020-c.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// https://atcoder.jp/contests/agc020/tasks/agc020_c
2+
//
3+
// 以下のクレートを使用。
4+
// - `bitset-fixed`
5+
// - `proconio`
6+
7+
use bitset_fixed::BitSet;
8+
use proconio::input;
9+
10+
fn main() {
11+
// `proconio::input!`。
12+
//
13+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
14+
input! {
15+
r#as: [usize],
16+
}
17+
18+
// `bitset-fixed`のREADMEにある解法。
19+
20+
let sum = r#as.iter().sum::<usize>();
21+
22+
// サイズ`sum + 1`のbit setに`fixed_bitset::BitSet`を使う。
23+
// これは`fixedbitset::FixedBitSet`と違いビットシフトが可能。
24+
// (`bitvec`クレートだと可能。提案しておけばよかったか..)
25+
//
26+
// https://docs.rs/bitset-fixed/0.1/bitset_fixed/struct.BitSet.html
27+
let mut dp = BitSet::new(sum + 1);
28+
dp.set(0, true);
29+
for a in r#as {
30+
dp |= &(&dp << a);
31+
}
32+
33+
let ans = ((sum + 1) / 2..).find(|&i| dp[i]).unwrap();
34+
println!("{}", ans);
35+
}

test-examples.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ url = "https://atcoder.jp/contests/abc160/tasks/abc160_e"
226226
matching = "Words"
227227
meta = { using = ["itertools", "proconio"] }
228228

229+
[examples.agc020-c]
230+
type = "Normal"
231+
name = "AGC020: C - Median Sum"
232+
url = "https://atcoder.jp/contests/agc020/tasks/agc020_c"
233+
matching = "Words"
234+
meta = { using = ["bitset-fixed", "proconio"] }
235+
229236
[examples.agc023-a]
230237
type = "Normal"
231238
name = "AGC023: A - Zero-Sum Ranges"

0 commit comments

Comments
 (0)