Skip to content

Commit 5ba7d01

Browse files
authored
Merge pull request #39 from qryxip/ja-all-enabled-more-tests
More tests (or rather, examples)
2 parents 09aa89d + 5b68983 commit 5ba7d01

File tree

121 files changed

+2235
-1117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+2235
-1117
lines changed

.cargo/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[alias]
22
dep-tests = ["run", "--manifest-path", "./tools/dep-tests/Cargo.toml", "--"]
3-
test-with-generated-opts = ["run", "--manifest-path", "./tools/test-with-generated-opts/Cargo.toml", "--"]
3+
test-examples = ["run", "--manifest-path", "./tools/test-examples/Cargo.toml", "--"]

.github/workflows/ci.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,25 @@ jobs:
4343
command: fmt
4444
args: --manifest-path ./tools/dep-tests/Cargo.toml -- --check
4545

46-
- name: '`cargo fmt --manifest-path ./tools/test-with-generated-opts/Cargo.toml -- --check`'
46+
- name: '`cargo fmt --manifest-path ./tools/test-examples/Cargo.toml -- --check`'
4747
uses: actions-rs/cargo@v1
4848
with:
4949
command: fmt
50-
args: --manifest-path ./tools/test-with-generated-opts/Cargo.toml -- --check
50+
args: --manifest-path ./tools/test-examples/Cargo.toml -- --check
5151

52-
test-with-generated-opts:
53-
name: test-with-generated-opts
52+
test-examples:
53+
name: test-examples
5454
runs-on: ubuntu-18.04
5555

5656
steps:
5757
- name: Checkout
5858
uses: actions/checkout@v1
5959

60+
- name: setup-python
61+
uses: actions/setup-python@v1
62+
with:
63+
python-version: '3.8'
64+
6065
- name: rust-toolchain
6166
uses: actions-rs/toolchain@v1
6267
with:
@@ -70,25 +75,22 @@ jobs:
7075
command: install
7176
args: --git https://github.com/rust-lang-ja/atcoder-rustc-dep-option-generator
7277

73-
- name: '`cargo clippy --all-features --manifest-path ./tools/test-with-generated-opts/Cargo.toml -- -D warnings`'
78+
- name: '`cargo clippy --all-features --manifest-path ./tools/test-examples/Cargo.toml -- -D warnings`'
7479
uses: actions-rs/cargo@v1
7580
with:
7681
command: clippy
77-
args: --all-features --manifest-path ./tools/test-with-generated-opts/Cargo.toml -- -D warnings
82+
args: --all-features --manifest-path ./tools/test-examples/Cargo.toml -- -D warnings
7883

7984
- name: '`cargo build --all-features --release`'
8085
uses: actions-rs/cargo@v1
8186
with:
8287
command: build
8388
args: --all-features --release
8489

85-
- name: '`chmod -R a=rX-w ./target`'
86-
run: chmod -R a=rX-w ./target
87-
88-
- name: '`cargo test-with-generated-opts`'
90+
- name: '`cargo test-examples`'
8991
uses: actions-rs/cargo@v1
9092
with:
91-
command: test-with-generated-opts
93+
command: test-examples
9294

9395
build:
9496
strategy:
@@ -176,17 +178,17 @@ jobs:
176178
override: true
177179
profile: default
178180

179-
- name: '`cargo clippy ${{ matrix.features }} -- -D warnings`'
181+
- name: '`cargo clippy --all-targets --profile test ${{ matrix.features }} -- -D warnings`'
180182
uses: actions-rs/cargo@v1
181183
with:
182184
command: clippy
183-
args: ${{ matrix.features }} -- -D warnings
185+
args: --all-targets --profile test ${{ matrix.features }} -- -D warnings
184186

185-
- name: '`cargo test ${{ matrix.features }} --no-fail-fast`'
187+
- name: '`cargo test --all-targets ${{ matrix.features }} --no-fail-fast`'
186188
uses: actions-rs/cargo@v1
187189
with:
188190
command: test
189-
args: ${{ matrix.features }} --no-fail-fast
191+
args: --all-targets ${{ matrix.features }} --no-fail-fast
190192

191193
- name: '`cargo run --release`'
192194
uses: actions-rs/cargo@v1

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/tools/dep-tests/Cargo.lock
2-
/tools/test-with-generated-opts/Cargo.lock
2+
/tools/test-examples/Cargo.lock
33
**/target/
44
**/*.rs.bk
55
**/*~

examples/abc054-c.rs

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,21 @@
11
// https://atcoder.jp/contests/abc054/tasks/abc054_c
22

3-
use petgraph::csr::Csr;
4-
use petgraph::Undirected;
3+
use itertools::Itertools as _;
4+
use petgraph::graph::UnGraph;
5+
use proconio::input;
6+
use proconio::marker::Usize1;
57

68
fn main() {
7-
// use std::io::{self, Read as _};
8-
//
9-
// let mut input = "".to_owned();
10-
// io::stdin().read_to_string(&mut input).unwrap();
11-
// let mut input = input.split_whitespace();
12-
// macro_rules! read {
13-
// ([$t:tt; $n:expr]) => {
14-
// (0..$n).map(|_| read!($t)).collect::<Vec<_>>()
15-
// };
16-
// (($($t:tt),+)) => {
17-
// ($(read!($t)),*)
18-
// };
19-
// (_1based) => {
20-
// read!(usize) - 1
21-
// };
22-
// (_bytes) => {
23-
// read!(String).into_bytes()
24-
// };
25-
// ($ty:ty) => {
26-
// input.next().unwrap().parse::<$ty>().unwrap()
27-
// };
28-
// }
29-
//
30-
// let (n, m) = read!((usize, usize));
31-
// let mut abs = read!([(_1based, _1based); m]);
32-
33-
use proconio::input;
34-
use proconio::marker::Usize1;
35-
369
input! {
3710
n: usize,
38-
m: usize,
39-
mut abs: [(Usize1, Usize1); m],
11+
abs: [(Usize1, Usize1)],
4012
}
4113

42-
abs.sort();
43-
let mut g = Csr::<(), (), Undirected, usize>::with_nodes(n);
44-
for (a, b) in abs {
45-
g.add_edge(a, b, ());
46-
}
47-
let mut ans = 0;
48-
let mut es = (0..n).collect::<Vec<_>>();
49-
permutohedron::heap_recursive(&mut es, |es| {
50-
if es[0] == 0 && es.windows(2).all(|w| g.contains_edge(w[0], w[1])) {
51-
ans += 1;
52-
}
53-
});
14+
let graph = UnGraph::<(), (), usize>::from_edges(abs);
15+
let ans = graph
16+
.node_indices()
17+
.permutations(n)
18+
.filter(|p| p[0].index() == 0 && p.windows(2).all(|w| graph.contains_edge(w[0], w[1])))
19+
.count();
5420
println!("{}", ans);
5521
}

examples/abc057-b-naive.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// https://atcoder.jp/contests/abc057/tasks/abc057_b
2+
3+
use std::io::{self, Read};
4+
5+
fn main() {
6+
let mut input = read_to_static(io::stdin()).split_whitespace();
7+
macro_rules! read {
8+
([$tt:tt]) => (read!([$tt; read!(usize)]));
9+
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
10+
(($($tt:tt),+)) => (($(read!($tt)),*));
11+
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
12+
}
13+
14+
let (n, m) = read!((usize, usize));
15+
let (abs, cds) = read!(([(i64, i64); n], [(i64, i64); m]));
16+
17+
for (a, b) in abs {
18+
let j = (0..m)
19+
.min_by_key(|&j| {
20+
let (c, d) = cds[j];
21+
(a - c).abs() + (b - d).abs()
22+
})
23+
.unwrap();
24+
println!("{}", j + 1);
25+
}
26+
}
27+
28+
fn read_to_static(mut source: impl Read) -> &'static str {
29+
let mut input = "".to_owned();
30+
source.read_to_string(&mut input).unwrap();
31+
Box::leak(input.into_boxed_str())
32+
}

examples/abc057-b-proconio.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// https://atcoder.jp/contests/abc057/tasks/abc057_b
2+
3+
use proconio::input;
4+
5+
fn main() {
6+
input! {
7+
n: usize,
8+
m: usize,
9+
abs: [(i64, i64); n],
10+
cds: [(i64, i64); m],
11+
}
12+
13+
for (a, b) in abs {
14+
let j = (0..m)
15+
.min_by_key(|&j| {
16+
let (c, d) = cds[j];
17+
(a - c).abs() + (b - d).abs()
18+
})
19+
.unwrap();
20+
println!("{}", j + 1);
21+
}
22+
}

examples/abc057-b-text-io.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// https://atcoder.jp/contests/abc057/tasks/abc057_b
2+
3+
#![allow(clippy::many_single_char_names, clippy::try_err)]
4+
5+
use text_io::{read, try_read, try_scan};
6+
7+
fn main() {
8+
let n: usize = read!();
9+
let m: usize = read!();
10+
let abs = (0..n)
11+
.map(|_| (read!(), read!()))
12+
.collect::<Vec<(i64, i64)>>();
13+
let cds = (0..m)
14+
.map(|_| (read!(), read!()))
15+
.collect::<Vec<(i64, i64)>>();
16+
17+
for (a, b) in abs {
18+
let j = (0..m)
19+
.min_by_key(|&j| {
20+
let (c, d) = cds[j];
21+
(a - c).abs() + (b - d).abs()
22+
})
23+
.unwrap();
24+
println!("{}", j + 1);
25+
}
26+
}

examples/abc057-b-whiteread.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// https://atcoder.jp/contests/abc057/tasks/abc057_b
2+
3+
use whiteread::Reader;
4+
5+
fn main() {
6+
let mut rdr = Reader::from_stdin_naive();
7+
8+
let (n, m) = rdr.p::<(usize, usize)>();
9+
let abs = (0..n).map(|_| rdr.p()).collect::<Vec<(i64, i64)>>();
10+
let cds = (0..m).map(|_| rdr.p()).collect::<Vec<(i64, i64)>>();
11+
12+
for (a, b) in abs {
13+
let j = (0..m)
14+
.min_by_key(|&j| {
15+
let (c, d) = cds[j];
16+
(a - c).abs() + (b - d).abs()
17+
})
18+
.unwrap();
19+
println!("{}", j + 1);
20+
}
21+
}

examples/abc073-d.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// https://atcoder.jp/contests/abc073/tasks/abc073_d
2+
3+
use itertools::Itertools as _;
4+
use num::traits::One;
5+
use petgraph::graph::{IndexType, NodeIndex, UnGraph};
6+
use proconio::input;
7+
use proconio::source::{Readable, Source};
8+
9+
use std::collections::HashMap;
10+
use std::io::BufRead;
11+
use std::marker::PhantomData;
12+
use std::ops::Sub;
13+
14+
fn main() {
15+
input! {
16+
_n: usize,
17+
m: usize,
18+
r: usize,
19+
rs: [NodeIndex1<u32>; r],
20+
abcs: [(NodeIndex1<u32>, NodeIndex1<u32>, u32); m],
21+
}
22+
23+
let graph = UnGraph::<(), u32>::from_edges(abcs);
24+
25+
let dijkstra = rs
26+
.iter()
27+
.map(|&r| {
28+
let dijkstra = petgraph::algo::dijkstra(&graph, r, None, |e| *e.weight());
29+
(r, dijkstra)
30+
})
31+
.collect::<HashMap<_, _>>();
32+
33+
let ans = rs
34+
.into_iter()
35+
.permutations(r)
36+
.map(|rs| rs.windows(2).map(|w| dijkstra[&w[0]][&w[1]]).sum::<u32>())
37+
.min()
38+
.unwrap();
39+
println!("{}", ans);
40+
}
41+
42+
struct NodeIndex1<Ix>(PhantomData<fn() -> Ix>);
43+
44+
impl<Ix: IndexType + Readable<Output = Ix> + One + Sub<Output = Ix>> Readable for NodeIndex1<Ix> {
45+
type Output = NodeIndex<Ix>;
46+
47+
fn read<R: BufRead, S: Source<R>>(source: &mut S) -> NodeIndex<Ix> {
48+
NodeIndex::from(Ix::read(source) - Ix::one())
49+
}
50+
}

examples/abc084-d.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

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