Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f74ad5

Browse files
committed
Add an example for ABC122-C
1 parent 2ce3682 commit 9f74ad5

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

examples/abc122-c.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// https://atcoder.jp/contests/abc122/tasks/abc122_c
2+
//
3+
// 以下のクレートを使用。
4+
//
5+
// - `itertools-num`
6+
// - `proconio`
7+
8+
use itertools_num::ItertoolsNum as _;
9+
use proconio::marker::{Bytes, Usize1};
10+
use proconio::{fastout, input};
11+
12+
use std::iter;
13+
14+
// `#[proconio::fastout]`で`println!`を置き換える。
15+
//
16+
// https://docs.rs/proconio-derive/0.1/proconio_derive/attr.fastout.html
17+
#[fastout]
18+
fn main() {
19+
// `proconio::input!`では使わない値を`_`とすることができる。
20+
//
21+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
22+
input! {
23+
_: usize,
24+
q: usize,
25+
s: Bytes,
26+
lrs: [(Usize1, Usize1); q],
27+
}
28+
29+
// `<_ as itertools_num::ItertoolsNum>::cumsum`で作られた一次元累積和のイテレータを、先頭に`0`を挿入した上で`Vec<_>`にする。
30+
//
31+
// https://docs.rs/itertools-num/0.1/itertools_num/trait.ItertoolsNum.html#method.cumsum
32+
let cumsum = iter::once(0)
33+
.chain(s.windows(2).map(|w| (w == b"AC").into()))
34+
.cumsum()
35+
.collect::<Vec<u32>>();
36+
37+
for (l, r) in lrs {
38+
println!("{}", cumsum[r] - cumsum[l]);
39+
}
40+
}

test-examples.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ url = "https://atcoder.jp/contests/abc121/tasks/abc121_b"
100100
matching = "Words"
101101
meta = { using = ["whiteread"] }
102102

103+
[examples.abc122-c]
104+
type = "Normal"
105+
name = "ABC122: C - GeT AC"
106+
url = "https://atcoder.jp/contests/abc122/tasks/abc122_c"
107+
matching = "Words"
108+
meta = { using = ["itertools-num", "proconio"] }
109+
103110
[examples.abc129-f]
104111
type = "Normal"
105112
name = "ABC129: F - Takahashi's Basics in Education and Learning"

0 commit comments

Comments
 (0)