Skip to content

More tests (or rather, examples) #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2d401c6
Add a test for ABC129-F
qryxip Dec 19, 2019
5b356b2
Add a test for ABC077/ARC084-C
qryxip Dec 19, 2019
2beb8ac
Add a test for ABC144-D
qryxip Dec 20, 2019
1aa9c37
Add a test for ABC057-B
qryxip Dec 20, 2019
3d78a59
Add a test for ABC118-B
qryxip Dec 20, 2019
3a72838
Add a test for ABC121-B
qryxip Dec 20, 2019
4be7fea
Remove `proconio::input!` from the examples other than `abc121-b`
qryxip Dec 20, 2019
833ebab
Move ./examples/tests.ron to ./test-with-generated-opts.toml
qryxip Dec 20, 2019
af6176b
Modify the format of test-with-generated-opts.toml
qryxip Dec 20, 2019
b43ac7e
Remove `practice-a` from the examples
qryxip Dec 20, 2019
ed595a6
Scrape sample cases from AtCoder
qryxip Dec 21, 2019
ad381fd
Add an example for sumitrust2019-C
qryxip Dec 22, 2019
80ac51c
Modify an example
qryxip Jan 10, 2020
0ff2ac1
Remove comments
qryxip Jan 10, 2020
a823fa6
Add an example for ABC150-D
qryxip Jan 10, 2020
68c8e11
Add an example for ABC141-C
qryxip Jan 11, 2020
bd0b0db
Note which example uses which crates
qryxip Jan 11, 2020
931fda8
Remove `fastout`s from some examples
qryxip Jan 11, 2020
3d74af8
More input examples
qryxip Jan 11, 2020
21b945c
Remove dead arms
qryxip Jan 11, 2020
012a8b7
Modify some examples
qryxip Jan 12, 2020
03a8d14
Add an example for ABC151-D
qryxip Jan 12, 2020
2df3e1e
Collapse `read!`s
qryxip Jan 14, 2020
61618c0
Add dead arms again
qryxip Jan 14, 2020
e80232e
`leak` strings to carve out to functions
qryxip Jan 14, 2020
2579231
'MacroTranscriber' can be `(..)`
qryxip Jan 15, 2020
b1d122f
Remove 'defmac's
qryxip Jan 15, 2020
39208de
Add examples for practice-A
qryxip Jan 15, 2020
3823bf1
Modify `read!`s
qryxip Jan 15, 2020
dc9129d
Modify `abc054-c`
qryxip Jan 15, 2020
02e21ec
Add an example for ABC142-C
qryxip Jan 15, 2020
180ad35
Add an example for ABC073-D
qryxip Jan 15, 2020
f204639
Modify `abc151-d`
qryxip Jan 15, 2020
65632fe
Add examples for practice-B
qryxip Jan 16, 2020
f157fc7
Test `practice-b-*`
qryxip Jan 16, 2020
211ceb2
Add `--all-targets` flags
qryxip Jan 17, 2020
e538851
`test-with-generated-opts` → `test-examples`
qryxip Jan 24, 2020
5340eed
Stop using some of the crates
qryxip Jan 24, 2020
5b68983
Use proconio in most of the examples
qryxip Jan 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[alias]
dep-tests = ["run", "--manifest-path", "./tools/dep-tests/Cargo.toml", "--"]
test-with-generated-opts = ["run", "--manifest-path", "./tools/test-with-generated-opts/Cargo.toml", "--"]
test-examples = ["run", "--manifest-path", "./tools/test-examples/Cargo.toml", "--"]
32 changes: 17 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,25 @@ jobs:
command: fmt
args: --manifest-path ./tools/dep-tests/Cargo.toml -- --check

- name: '`cargo fmt --manifest-path ./tools/test-with-generated-opts/Cargo.toml -- --check`'
- name: '`cargo fmt --manifest-path ./tools/test-examples/Cargo.toml -- --check`'
uses: actions-rs/cargo@v1
with:
command: fmt
args: --manifest-path ./tools/test-with-generated-opts/Cargo.toml -- --check
args: --manifest-path ./tools/test-examples/Cargo.toml -- --check

test-with-generated-opts:
name: test-with-generated-opts
test-examples:
name: test-examples
runs-on: ubuntu-18.04

steps:
- name: Checkout
uses: actions/checkout@v1

- name: setup-python
uses: actions/setup-python@v1
with:
python-version: '3.8'

- name: rust-toolchain
uses: actions-rs/toolchain@v1
with:
Expand All @@ -70,25 +75,22 @@ jobs:
command: install
args: --git https://github.com/rust-lang-ja/atcoder-rustc-dep-option-generator

- name: '`cargo clippy --all-features --manifest-path ./tools/test-with-generated-opts/Cargo.toml -- -D warnings`'
- name: '`cargo clippy --all-features --manifest-path ./tools/test-examples/Cargo.toml -- -D warnings`'
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features --manifest-path ./tools/test-with-generated-opts/Cargo.toml -- -D warnings
args: --all-features --manifest-path ./tools/test-examples/Cargo.toml -- -D warnings

- name: '`cargo build --all-features --release`'
uses: actions-rs/cargo@v1
with:
command: build
args: --all-features --release

- name: '`chmod -R a=rX-w ./target`'
run: chmod -R a=rX-w ./target

- name: '`cargo test-with-generated-opts`'
- name: '`cargo test-examples`'
uses: actions-rs/cargo@v1
with:
command: test-with-generated-opts
command: test-examples

build:
strategy:
Expand Down Expand Up @@ -176,17 +178,17 @@ jobs:
override: true
profile: default

- name: '`cargo clippy ${{ matrix.features }} -- -D warnings`'
- name: '`cargo clippy --all-targets --profile test ${{ matrix.features }} -- -D warnings`'
uses: actions-rs/cargo@v1
with:
command: clippy
args: ${{ matrix.features }} -- -D warnings
args: --all-targets --profile test ${{ matrix.features }} -- -D warnings

- name: '`cargo test ${{ matrix.features }} --no-fail-fast`'
- name: '`cargo test --all-targets ${{ matrix.features }} --no-fail-fast`'
uses: actions-rs/cargo@v1
with:
command: test
args: ${{ matrix.features }} --no-fail-fast
args: --all-targets ${{ matrix.features }} --no-fail-fast

- name: '`cargo run --release`'
uses: actions-rs/cargo@v1
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/tools/dep-tests/Cargo.lock
/tools/test-with-generated-opts/Cargo.lock
/tools/test-examples/Cargo.lock
**/target/
**/*.rs.bk
**/*~
56 changes: 11 additions & 45 deletions examples/abc054-c.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,21 @@
// https://atcoder.jp/contests/abc054/tasks/abc054_c

use petgraph::csr::Csr;
use petgraph::Undirected;
use itertools::Itertools as _;
use petgraph::graph::UnGraph;
use proconio::input;
use proconio::marker::Usize1;

fn main() {
// use std::io::{self, Read as _};
//
// let mut input = "".to_owned();
// io::stdin().read_to_string(&mut input).unwrap();
// let mut input = input.split_whitespace();
// macro_rules! read {
// ([$t:tt; $n:expr]) => {
// (0..$n).map(|_| read!($t)).collect::<Vec<_>>()
// };
// (($($t:tt),+)) => {
// ($(read!($t)),*)
// };
// (_1based) => {
// read!(usize) - 1
// };
// (_bytes) => {
// read!(String).into_bytes()
// };
// ($ty:ty) => {
// input.next().unwrap().parse::<$ty>().unwrap()
// };
// }
//
// let (n, m) = read!((usize, usize));
// let mut abs = read!([(_1based, _1based); m]);

use proconio::input;
use proconio::marker::Usize1;

input! {
n: usize,
m: usize,
mut abs: [(Usize1, Usize1); m],
abs: [(Usize1, Usize1)],
}

abs.sort();
let mut g = Csr::<(), (), Undirected, usize>::with_nodes(n);
for (a, b) in abs {
g.add_edge(a, b, ());
}
let mut ans = 0;
let mut es = (0..n).collect::<Vec<_>>();
permutohedron::heap_recursive(&mut es, |es| {
if es[0] == 0 && es.windows(2).all(|w| g.contains_edge(w[0], w[1])) {
ans += 1;
}
});
let graph = UnGraph::<(), (), usize>::from_edges(abs);
let ans = graph
.node_indices()
.permutations(n)
.filter(|p| p[0].index() == 0 && p.windows(2).all(|w| graph.contains_edge(w[0], w[1])))
.count();
println!("{}", ans);
}
32 changes: 32 additions & 0 deletions examples/abc057-b-naive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// https://atcoder.jp/contests/abc057/tasks/abc057_b

use std::io::{self, Read};

fn main() {
let mut input = read_to_static(io::stdin()).split_whitespace();
macro_rules! read {
([$tt:tt]) => (read!([$tt; read!(usize)]));
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
(($($tt:tt),+)) => (($(read!($tt)),*));
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
}

let (n, m) = read!((usize, usize));
let (abs, cds) = read!(([(i64, i64); n], [(i64, i64); m]));

for (a, b) in abs {
let j = (0..m)
.min_by_key(|&j| {
let (c, d) = cds[j];
(a - c).abs() + (b - d).abs()
})
.unwrap();
println!("{}", j + 1);
}
}

fn read_to_static(mut source: impl Read) -> &'static str {
let mut input = "".to_owned();
source.read_to_string(&mut input).unwrap();
Box::leak(input.into_boxed_str())
}
22 changes: 22 additions & 0 deletions examples/abc057-b-proconio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// https://atcoder.jp/contests/abc057/tasks/abc057_b

use proconio::input;

fn main() {
input! {
n: usize,
m: usize,
abs: [(i64, i64); n],
cds: [(i64, i64); m],
}

for (a, b) in abs {
let j = (0..m)
.min_by_key(|&j| {
let (c, d) = cds[j];
(a - c).abs() + (b - d).abs()
})
.unwrap();
println!("{}", j + 1);
}
}
26 changes: 26 additions & 0 deletions examples/abc057-b-text-io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// https://atcoder.jp/contests/abc057/tasks/abc057_b

#![allow(clippy::many_single_char_names, clippy::try_err)]

use text_io::{read, try_read, try_scan};

fn main() {
let n: usize = read!();
let m: usize = read!();
let abs = (0..n)
.map(|_| (read!(), read!()))
.collect::<Vec<(i64, i64)>>();
let cds = (0..m)
.map(|_| (read!(), read!()))
.collect::<Vec<(i64, i64)>>();

for (a, b) in abs {
let j = (0..m)
.min_by_key(|&j| {
let (c, d) = cds[j];
(a - c).abs() + (b - d).abs()
})
.unwrap();
println!("{}", j + 1);
}
}
21 changes: 21 additions & 0 deletions examples/abc057-b-whiteread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// https://atcoder.jp/contests/abc057/tasks/abc057_b

use whiteread::Reader;

fn main() {
let mut rdr = Reader::from_stdin_naive();

let (n, m) = rdr.p::<(usize, usize)>();
let abs = (0..n).map(|_| rdr.p()).collect::<Vec<(i64, i64)>>();
let cds = (0..m).map(|_| rdr.p()).collect::<Vec<(i64, i64)>>();

for (a, b) in abs {
let j = (0..m)
.min_by_key(|&j| {
let (c, d) = cds[j];
(a - c).abs() + (b - d).abs()
})
.unwrap();
println!("{}", j + 1);
}
}
50 changes: 50 additions & 0 deletions examples/abc073-d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// https://atcoder.jp/contests/abc073/tasks/abc073_d

use itertools::Itertools as _;
use num::traits::One;
use petgraph::graph::{IndexType, NodeIndex, UnGraph};
use proconio::input;
use proconio::source::{Readable, Source};

use std::collections::HashMap;
use std::io::BufRead;
use std::marker::PhantomData;
use std::ops::Sub;

fn main() {
input! {
_n: usize,
m: usize,
r: usize,
rs: [NodeIndex1<u32>; r],
abcs: [(NodeIndex1<u32>, NodeIndex1<u32>, u32); m],
}

let graph = UnGraph::<(), u32>::from_edges(abcs);

let dijkstra = rs
.iter()
.map(|&r| {
let dijkstra = petgraph::algo::dijkstra(&graph, r, None, |e| *e.weight());
(r, dijkstra)
})
.collect::<HashMap<_, _>>();

let ans = rs
.into_iter()
.permutations(r)
.map(|rs| rs.windows(2).map(|w| dijkstra[&w[0]][&w[1]]).sum::<u32>())
.min()
.unwrap();
println!("{}", ans);
}

struct NodeIndex1<Ix>(PhantomData<fn() -> Ix>);

impl<Ix: IndexType + Readable<Output = Ix> + One + Sub<Output = Ix>> Readable for NodeIndex1<Ix> {
type Output = NodeIndex<Ix>;

fn read<R: BufRead, S: Source<R>>(source: &mut S) -> NodeIndex<Ix> {
NodeIndex::from(Ix::read(source) - Ix::one())
}
}
52 changes: 0 additions & 52 deletions examples/abc084-d.rs

This file was deleted.

Loading