Skip to content

Commit 2ce3682

Browse files
committed
Add an example for AGC023-A
1 parent 0591e37 commit 2ce3682

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

examples/agc023-a.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// https://atcoder.jp/contests/agc023/tasks/agc023_a
2+
//
3+
// 以下のクレートを使用。
4+
//
5+
// - `itertools-num`
6+
// - `maplit`
7+
// - `proconio`
8+
9+
use itertools_num::ItertoolsNum as _;
10+
use maplit::hashmap;
11+
use proconio::input;
12+
13+
fn main() {
14+
// `proconio::input!`。
15+
//
16+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
17+
input! {
18+
r#as: [i64],
19+
}
20+
21+
// `0`が一つが入ったcounterを`maplit::hashmap!`で作る。
22+
//
23+
// https://docs.rs/maplit/1/maplit/macro.hashmap.html
24+
let mut counter = hashmap!(0 => 1u64); // `0`が一つが入ったcounterを`maplit::hashmap!`で作る。
25+
26+
// `<_ as itertools_num::ItertoolsNum>::cumsum`で作られた一次元累積和のイテレータを、`Vec`にせずにそのまま`for`文で回す。
27+
//
28+
// https://docs.rs/itertools-num/0.1/itertools_num/trait.ItertoolsNum.html#method.cumsum
29+
for sum in r#as.into_iter().cumsum() {
30+
*counter.entry(sum).or_insert(0) += 1;
31+
}
32+
33+
let ans = counter.values().map(|v| v * (v - 1) / 2).sum::<u64>();
34+
println!("{}", ans);
35+
}

test-examples.toml

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

145+
[examples.agc023-a]
146+
type = "Normal"
147+
name = "AGC023: A - Zero-Sum Ranges"
148+
url = "https://atcoder.jp/contests/agc023/tasks/agc023_a"
149+
matching = "Words"
150+
meta = { using = ["itertools-num", "maplit", "proconio"] }
151+
145152
[examples.apg4b-a]
146153
type = "Normal"
147154
name = "APG4b: A - 1.00.はじめに"

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