Skip to content

Commit 34c699d

Browse files
committed
Add an example for ABC154-D
1 parent bd67d37 commit 34c699d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

examples/abc154-d.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// https://atcoder.jp/contests/abc154/tasks/abc154_d
2+
//
3+
// 以下のクレートを使用。
4+
//
5+
// - `itertools-num`
6+
// - `ordered-float`
7+
// - `proconio`
8+
9+
use itertools_num::ItertoolsNum as _;
10+
use ordered_float::NotNan;
11+
use proconio::input;
12+
13+
use std::iter;
14+
15+
// `NotNan<f64>: FromStr`であり、四則演算の右辺に`f64`が許されているので`NotNan`のリテラルが必要になることは少ない。
16+
// 必要な場合このようなマクロや関数等を用意しておくと見た目は軽くなる。
17+
macro_rules! notnan(($lit:literal) => (NotNan::new($lit).unwrap()));
18+
19+
fn main() {
20+
// `proconio::input!`は(オリジナルの`input!`もそうだが)`FromStr`を実装する値なら何でも読める。
21+
// ここでは{ p_i }を`ordered_float::NotNan<f64>`として受け取る。
22+
//
23+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
24+
// https://docs.rs/ordered-float/1/ordered_float/struct.NotNan.html
25+
input! {
26+
n: usize,
27+
k: usize,
28+
ps: [NotNan<_>; n],
29+
}
30+
31+
// 先頭に`0`を挿入した一次元累積和のイテレータを`<_ as itertools_num::ItertoolsNum>::cumsum`で作り、`Vec<_>`にする。
32+
//
33+
// https://docs.rs/itertools-num/0.1/itertools_num/trait.ItertoolsNum.html#method.cumsum
34+
let ans = iter::once(notnan!(0.0))
35+
.chain(ps.into_iter().map(|p| (p + 1.0) / 2.0))
36+
.cumsum()
37+
.collect::<Vec<NotNan<_>>>()
38+
.windows(k + 1)
39+
.map(|w| w[w.len() - 1] - w[0])
40+
.max()
41+
.unwrap();
42+
println!("{}", ans);
43+
}

test-examples.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ url = "https://atcoder.jp/contests/abc151/tasks/abc151_d"
156156
matching = "Words"
157157
meta = { using = ["itertools", "ndarray", "proconio", "smallvec"] }
158158

159+
[examples.abc154-d]
160+
type = "Normal"
161+
name = "ABC154: D - Dice in Line"
162+
url = "https://atcoder.jp/contests/abc154/tasks/abc154_d"
163+
matching = { FloatOr = { abs = 1e-6, rel = 1e-6 } }
164+
meta = { using = ["itertools-num", "ordered-float", "proconio"] }
165+
159166
[examples.agc023-a]
160167
type = "Normal"
161168
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