Skip to content

Commit c867fec

Browse files
committed
Add an example for ABC166-B
1 parent 1574f54 commit c867fec

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

examples/abc166-b.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// https://atcoder.jp/contests/abc166/tasks/abc166_b
2+
//
3+
// 以下のクレートを使用。
4+
// - `itertools`
5+
// - `proconio`
6+
7+
use itertools::Itertools as _;
8+
use proconio::{input, marker::Usize1};
9+
10+
fn main() {
11+
// `proconio::input!`には`n: usize, xs: [T; n]`のかわりに`xs: [T]`と書ける機能がある。
12+
// この機能を用いることで今回のような入力をシンプルにできる。
13+
//
14+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
15+
input! {
16+
n: usize,
17+
ass: [[Usize1]],
18+
}
19+
20+
// `Itertools::unique`で要素の重複が省かれたイテレータが手に入る。
21+
//
22+
// https://docs.rs/itertools/0.9.0/itertools/trait.Itertools.html#method.unique
23+
let ans = n - ass.into_iter().flatten().unique().count();
24+
25+
// あるいは`fixedbitset::FixedBitSet`を使っても良い。
26+
// `FixedBitSet`は`FromIterator<usize>`であり、`count_ones`という「`1`」を数えるメソッドを持つ。
27+
//
28+
// https://docs.rs/fixedbitset/0.2.0/fixedbitset/struct.FixedBitSet.html
29+
// https://docs.rs/fixedbitset/0.2.0/fixedbitset/struct.FixedBitSet.html#method.count_ones
30+
//use fixedbitset::FixedBitSet;
31+
//let ans = n - ass
32+
// .into_iter()
33+
// .flatten()
34+
// .collect::<FixedBitSet>()
35+
// .count_ones(..);
36+
37+
println!("{}", ans);
38+
}

test-examples.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ url = "https://atcoder.jp/contests/abc165/tasks/abc165_c"
247247
matching = "Words"
248248
meta = { using = ["itertools", "proconio"] }
249249

250+
[examples.abc166-b]
251+
type = "Normal"
252+
name = "ABC166 - B - Trick or Treat"
253+
url = "https://atcoder.jp/contests/abc166/tasks/abc166_b"
254+
matching = "Words"
255+
meta = { using = ["itertools", "proconio"] }
256+
250257
[examples.agc020-c]
251258
type = "Normal"
252259
name = "AGC020: C - Median Sum"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy