File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -226,6 +226,13 @@ url = "https://atcoder.jp/contests/abc160/tasks/abc160_e"
226
226
matching = " Words"
227
227
meta = { using = [" itertools" , " proconio" ] }
228
228
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
+
229
236
[examples .agc023-a ]
230
237
type = " Normal"
231
238
name = " AGC023: A - Zero-Sum Ranges"
You can’t perform that action at this time.
0 commit comments