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

Skip to content

Commit 1574f54

Browse files
committed
Add an example for ABC165-C
1 parent f25e972 commit 1574f54

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

examples/abc165-c.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// https://atcoder.jp/contests/abc165/tasks/abc165_c
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!`。
12+
//
13+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
14+
input! {
15+
n: usize,
16+
m: usize,
17+
abcds: [(Usize1, Usize1, usize, u64)],
18+
}
19+
20+
// `Itertools::combinations_with_replacement`で広義単調増加なAをすべて列挙する。
21+
// Pythonの同名な関数と同じ。
22+
//
23+
// https://docs.rs/itertools/0.9.0/itertools/trait.Itertools.html#method.combinations_with_replacement
24+
let ans = (0..m)
25+
.combinations_with_replacement(n)
26+
.map(|arr| {
27+
abcds
28+
.iter()
29+
.filter(|&&(a, b, c, _)| arr[b] - arr[a] == c)
30+
.map(|(_, _, _, d)| d)
31+
.sum::<u64>()
32+
})
33+
.max()
34+
.unwrap();
35+
println!("{}", ans);
36+
}

test-examples.toml

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

243+
[examples.abc165-c]
244+
type = "Normal"
245+
name = "ABC165 - C - Many Requirements"
246+
url = "https://atcoder.jp/contests/abc165/tasks/abc165_c"
247+
matching = "Words"
248+
meta = { using = ["itertools", "proconio"] }
249+
243250
[examples.agc020-c]
244251
type = "Normal"
245252
name = "AGC020: C - Median Sum"

0 commit comments

Comments
 (0)