Skip to content

Commit ee5ad20

Browse files
Recon and aizu (#25)
* add lca_aizu test * add is_prime test * add fenwick tree aizu test * add aizu dsu test * add dijk aizu * reorganize the lib * restructure the examples directory * Fix paths in cargo toml * fix clippy * test nits + increase TL to 20 seconds for is_prime test which is 1e8 log * fix clippy * supernit tests * fix * super nit * remove code coverage for now
1 parent 9992238 commit ee5ad20

File tree

28 files changed

+314
-99
lines changed

28 files changed

+314
-99
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ jobs:
6060
#
6161
# since all tests are rerun on every commit anyways, there's no need for
6262
# the .verify-helper/timestamps.remote.json file
63-
run: oj-verify all --tle 10 --jobs 4 --timeout 21600
63+
run: oj-verify all --tle 20 --jobs 4 --timeout 21600
6464
# https://doc.rust-lang.org/rustc/instrument-coverage.html
65-
- name: code coverage
66-
run: |
67-
cargo profdata -- merge -sparse default_*.profraw -o json5format.profdata
68-
cargo cov -- report --use-color --ignore-filename-regex='/.cargo/registry' --instr-profile=json5format.profdata $(find target/debug/examples -type f -executable)
69-
cargo cov -- export --ignore-filename-regex='/.cargo/registry' --instr-profile=json5format.profdata $(find target/debug/examples -type f -executable) | python -c "import sys, json; l=json.load(sys.stdin)['data'][0]['totals']['lines']; assert(l['count'] == l['covered'])"
65+
# - name: code coverage
66+
# run: |
67+
# cargo profdata -- merge -sparse default_*.profraw -o json5format.profdata
68+
# cargo cov -- report --use-color --ignore-filename-regex='/.cargo/registry' --instr-profile=json5format.profdata $(find target/debug/examples -type f -executable)
69+
# cargo cov -- export --ignore-filename-regex='/.cargo/registry' --instr-profile=json5format.profdata $(find target/debug/examples -type f -executable) | python -c "import sys, json; l=json.load(sys.stdin)['data'][0]['totals']['lines']; assert(l['count'] == l['covered'])"

Cargo.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,51 @@ edition = "2024"
99

1010
[dependencies]
1111
proconio = "0.4.5"
12+
13+
[[example]]
14+
name = "dsu_aizu"
15+
path = "examples/data_structures/dsu_aizu.rs"
16+
17+
[[example]]
18+
name = "dsu_yosupo"
19+
path = "examples/data_structures/dsu_yosupo.rs"
20+
21+
[[example]]
22+
name = "fenwick_aizu"
23+
path = "examples/data_structures/fenwick_aizu.rs"
24+
25+
[[example]]
26+
name = "fenwick_yosupo"
27+
path = "examples/data_structures/fenwick_yosupo.rs"
28+
29+
[[example]]
30+
name = "rmq"
31+
path = "examples/data_structures/rmq.rs"
32+
33+
[[example]]
34+
name = "dijk_aizu"
35+
path = "examples/graphs/dijk_aizu.rs"
36+
37+
[[example]]
38+
name = "dijk_yosupo"
39+
path = "examples/graphs/dijk_yosupo.rs"
40+
41+
[[example]]
42+
name = "lca_aizu"
43+
path = "examples/graphs/lca_aizu.rs"
44+
45+
[[example]]
46+
name = "lca_yosupo"
47+
path = "examples/graphs/lca_yosupo.rs"
48+
49+
[[example]]
50+
name = "binom"
51+
path = "examples/numbers/binom.rs"
52+
53+
[[example]]
54+
name = "primes_factorize"
55+
path = "examples/numbers/primes_factorize.rs"
56+
57+
[[example]]
58+
name = "primes_is_prime"
59+
path = "examples/numbers/primes_is_prime.rs"

examples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Testing Guidelines
2+
- tests are named `[algo].rs`
3+
- use both yosupo and aizu to test whenever possible because bugs have existed on one of the sites but not the other
4+
- when using both sites name the files `[algo]_yosupo.rs` and `[algo]_aizu.rs`
5+
- when only testing a specific function or componenet of some algorithm name the file `[algo]_[component].rs`
6+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// verification-helper: PROBLEM https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A
2+
3+
use proconio::input;
4+
use programming_team_code_rust::data_structures::dsu::DSU;
5+
6+
fn main() {
7+
input! {
8+
n: usize,
9+
queries: [(u8, usize, usize)],
10+
}
11+
12+
let mut dsu = DSU::new(n);
13+
for (kind, u, v) in queries {
14+
match kind {
15+
0 => {
16+
dsu.unite(u, v);
17+
}
18+
1 => println!("{}", u8::from(dsu.same(u, v))),
19+
_ => unreachable!(),
20+
}
21+
}
22+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/unionfind
22

33
use proconio::input;
4-
use programming_team_code_rust::dsu::DSU;
4+
use programming_team_code_rust::data_structures::dsu::DSU;
55

66
fn main() {
77
input! {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// verification-helper: PROBLEM https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B
2+
3+
use proconio::input;
4+
use programming_team_code_rust::data_structures::fenwick::Fenwick;
5+
6+
fn main() {
7+
input! {
8+
n: usize,
9+
q: usize,
10+
}
11+
let mut fenwick = Fenwick::<usize>::new(n);
12+
for _ in 0..q {
13+
input! { t: u8,
14+
}
15+
match t {
16+
0 => {
17+
input! {
18+
i: usize,
19+
x: usize,
20+
}
21+
fenwick.add(i - 1, x);
22+
}
23+
1 => {
24+
input! {
25+
le: usize,
26+
ri: usize,
27+
}
28+
println!("{}", fenwick.sum(le - 1..ri));
29+
}
30+
_ => unreachable!(),
31+
}
32+
}
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/point_add_range_sum
2+
3+
use proconio::input;
4+
use programming_team_code_rust::data_structures::fenwick::Fenwick;
5+
6+
fn main() {
7+
input! {
8+
n: usize,
9+
q: usize,
10+
}
11+
12+
let mut fenwick = Fenwick::<u64>::new(n);
13+
for i in 0..n {
14+
input! {
15+
x: u64,
16+
}
17+
fenwick.add(i, x);
18+
}
19+
20+
for _ in 0..q {
21+
input! {
22+
t: u8,
23+
}
24+
match t {
25+
0 => {
26+
input! {
27+
p: usize,
28+
x: u64,
29+
}
30+
fenwick.add(p, x);
31+
}
32+
1 => {
33+
input! {
34+
le: usize,
35+
ri: usize,
36+
}
37+
println!("{}", fenwick.sum(le..ri));
38+
}
39+
_ => unreachable!(),
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/staticrmq
22

33
use proconio::input;
4-
use programming_team_code_rust::rmq::RMQ;
4+
use programming_team_code_rust::data_structures::rmq::RMQ;
55

66
fn main() {
77
input! {
88
n: usize,
99
q: usize,
10-
a: [u32; n],
11-
queries: [(usize, usize); q],
10+
a: [usize; n],
1211
}
1312

1413
let rmq = RMQ::new(&a, std::cmp::min);
15-
for (le, ri) in queries {
14+
for _ in 0..q {
15+
input! {
16+
le: usize,
17+
ri: usize,
18+
}
1619
println!("{}", rmq.query(le..ri));
1720
}
1821
}

examples/graphs/dijk_aizu.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// verification-helper: PROBLEM https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
2+
3+
use proconio::input;
4+
use programming_team_code_rust::graphs::dijk::dijk;
5+
6+
fn main() {
7+
input! {
8+
n: usize,
9+
m: usize,
10+
s: usize,
11+
edges: [(usize, usize, u64); m],
12+
}
13+
14+
let mut adj = vec![vec![]; n];
15+
for (u, v, w) in edges {
16+
adj[u].push((v, w));
17+
}
18+
19+
let dist = dijk(&adj, s);
20+
for d in dist {
21+
if d == u64::MAX {
22+
println!("INF");
23+
} else {
24+
println!("{}", d);
25+
}
26+
}
27+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/shortest_path
22

33
use proconio::input;
4-
use programming_team_code_rust::dijk::dijk;
4+
use programming_team_code_rust::graphs::dijk::dijk;
55

66
fn main() {
77
input! {

0 commit comments

Comments
 (0)