Skip to content

Commit 8443283

Browse files
committed
Add an example for ABC154-E
1 parent 34c699d commit 8443283

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

examples/abc154-e.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// https://atcoder.jp/contests/abc154/tasks/abc154_e
2+
//
3+
// 以下のクレートを使用。
4+
//
5+
// - `num`
6+
// - `proconio`
7+
8+
use proconio::input;
9+
use proconio::marker::Bytes;
10+
11+
fn main() {
12+
// http://drken1215.hatenablog.com/entry/2020/02/09/225300
13+
14+
// `proconio::input!`。
15+
//
16+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
17+
input! {
18+
n: Bytes,
19+
k: usize,
20+
}
21+
22+
let n = n.into_iter().map(|d| (d - b'0').into()).collect();
23+
24+
println!("{}", St { n }.solve(0, k, false));
25+
26+
struct St {
27+
n: Vec<usize>,
28+
}
29+
30+
impl St {
31+
fn solve(&self, i: usize, j: usize, p: bool) -> usize {
32+
let Self { n } = self;
33+
34+
if j == 0 {
35+
1
36+
} else if i == n.len() {
37+
0
38+
} else if p {
39+
// 配列でのDPと違い、ここで打ち切れる。 ここで`num_integer::binomial`が使える。
40+
//
41+
// https://docs.rs/num-integer/0.1/num_integer/fn.binomial.html
42+
num::integer::binomial(n.len() - i, j) * 9usize.pow(j as u32)
43+
} else if n[i] == 0 {
44+
self.solve(i + 1, j, false)
45+
} else {
46+
self.solve(i + 1, j, true)
47+
+ self.solve(i + 1, j - 1, true) * (n[i] - 1)
48+
+ self.solve(i + 1, j - 1, false)
49+
}
50+
}
51+
}
52+
}

test-examples.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ url = "https://atcoder.jp/contests/abc154/tasks/abc154_d"
163163
matching = { FloatOr = { abs = 1e-6, rel = 1e-6 } }
164164
meta = { using = ["itertools-num", "ordered-float", "proconio"] }
165165

166+
[examples.abc154-e]
167+
type = "Normal"
168+
name = "ABC154: E - Almost Everywhere Zero"
169+
url = "https://atcoder.jp/contests/abc154/tasks/abc154_e"
170+
matching = "Words"
171+
meta = { using = ["num", "proconio"] }
172+
166173
[examples.agc023-a]
167174
type = "Normal"
168175
name = "AGC023: A - Zero-Sum Ranges"

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