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

Skip to content

Commit 614eae5

Browse files
committed
Add an example for panasonic2020_d
1 parent 0b05c4a commit 614eae5

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

examples/panasonic2020-d.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d
2+
//
3+
// 以下のクレートを使用。
4+
//
5+
// - `proconio`
6+
// - `smallvec`
7+
8+
use proconio::{fastout, input};
9+
use smallvec::{smallvec, Array, SmallVec};
10+
11+
use std::collections::VecDeque;
12+
use std::{cmp, str};
13+
14+
// `#[proconio::fastout]`で標準出力を高速化する。
15+
//
16+
// https://docs.rs/proconio-derive/0.1.6/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+
n: usize,
24+
}
25+
26+
// **高々**長さ10の文字列を`SmallVec<[u8; 10]>`で表わす。
27+
//
28+
// https://docs.rs/smallvec/1/smallvec/struct.SmallVec.html
29+
let mut queue = VecDeque::<(SmallVec<[_; 10]>, _)>::with_capacity(1 << 16);
30+
queue.push_back((smallvec![b'a'], b'a'));
31+
32+
while let Some((s, max)) = queue.pop_front() {
33+
if s.len() == n {
34+
println!("{}", str::from_utf8(&s).unwrap());
35+
} else {
36+
for c in b'a'..=max + 1 {
37+
queue.push_back((concat(s.clone(), c), cmp::max(c, max)));
38+
}
39+
}
40+
}
41+
}
42+
43+
fn concat<A: Array>(mut xs: SmallVec<A>, x: A::Item) -> SmallVec<A> {
44+
xs.push(x);
45+
xs
46+
}

test-examples.toml

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

244+
[examples.panasonic2020-d]
245+
type = "Normal"
246+
name = "Panasonic Programming Contest 2020: D - String Equivalence"
247+
url = "https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d"
248+
matching = "Words"
249+
meta = { using = ["proconio", "smallvec"] }
250+
244251
[examples.practice-a-naive]
245252
type = "Normal"
246253
name = "practice contest: A - Welcome to AtCoder"

0 commit comments

Comments
 (0)