Skip to content

Commit c78f007

Browse files
authored
Merge pull request rust-lang-ja#37 from qryxip/ja-all-enabled-more-tests
More tests
2 parents 85378b7 + 84afc96 commit c78f007

Some content is hidden

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

52 files changed

+634
-1
lines changed

examples/abc054-c.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// https://atcoder.jp/contests/abc054/tasks/abc054_c
2+
3+
use petgraph::csr::Csr;
4+
use petgraph::Undirected;
5+
6+
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+
36+
input! {
37+
n: usize,
38+
m: usize,
39+
mut abs: [(Usize1, Usize1); m],
40+
}
41+
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+
});
54+
println!("{}", ans);
55+
}

examples/abc084-d.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// https://atcoder.jp/contests/abc084/tasks/abc084_d
2+
3+
use itertools_num::ItertoolsNum as _;
4+
use primal::Sieve;
5+
6+
#[proconio::fastout]
7+
fn main() {
8+
// use std::io::{self, Read as _};
9+
//
10+
// let mut input = "".to_owned();
11+
// io::stdin().read_to_string(&mut input).unwrap();
12+
// let mut input = input.split_whitespace();
13+
// macro_rules! read {
14+
// ([$t:tt; $n:expr]) => {
15+
// (0..$n).map(|_| read!($t)).collect::<Vec<_>>()
16+
// };
17+
// (($($t:tt),+)) => {
18+
// ($(read!($t)),*)
19+
// };
20+
// (_1based) => {
21+
// read!(usize) - 1
22+
// };
23+
// (_bytes) => {
24+
// read!(String).into_bytes()
25+
// };
26+
// ($ty:ty) => {
27+
// input.next().unwrap().parse::<$ty>().unwrap()
28+
// };
29+
// }
30+
//
31+
// let q = read!(usize);
32+
// let lrs = read!([(usize, usize); q]);
33+
34+
use proconio::input;
35+
36+
input! {
37+
q: usize,
38+
lrs: [(usize, usize); q],
39+
}
40+
41+
// サンプルケースでしか試してないので嘘かもしれない。
42+
43+
let hi = lrs.iter().map(|&(_, r)| r).max().unwrap();
44+
let sieve = Sieve::new(hi);
45+
let nums = (0..=hi)
46+
.map(|k| u32::from(sieve.is_prime(k) && sieve.is_prime((k + 1) / 2)))
47+
.cumsum()
48+
.collect::<Vec<u32>>();
49+
for (l, r) in lrs {
50+
println!("{}", nums[r] - nums[l - 1]);
51+
}
52+
}

examples/abc142-d.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// https://atcoder.jp/contests/abc142/tasks/abc142_d
2+
3+
use primal::Sieve;
4+
5+
use std::cmp::max;
6+
use std::collections::HashSet;
7+
8+
fn main() {
9+
// use std::io::{self, Read as _};
10+
//
11+
// let mut input = "".to_owned();
12+
// io::stdin().read_to_string(&mut input).unwrap();
13+
// let mut input = input.split_whitespace();
14+
// macro_rules! read {
15+
// ([$t:tt; $n:expr]) => {
16+
// (0..$n).map(|_| read!($t)).collect::<Vec<_>>()
17+
// };
18+
// (($($t:tt),+)) => {
19+
// ($(read!($t)),*)
20+
// };
21+
// (_1based) => {
22+
// read!(usize) - 1
23+
// };
24+
// (_bytes) => {
25+
// read!(String).into_bytes()
26+
// };
27+
// ($ty:ty) => {
28+
// input.next().unwrap().parse::<$ty>().unwrap()
29+
// };
30+
// }
31+
//
32+
// let (n, m) = read!((usize, usize));
33+
34+
use proconio::input;
35+
36+
input! {
37+
a: usize,
38+
b: usize,
39+
}
40+
41+
// サンプルケースでしか試してないので嘘かもしれない。
42+
43+
let sieve = Sieve::new(num_integer::sqrt(max(a, b)));
44+
let bases = |k| -> HashSet<_> {
45+
sieve
46+
.factor(k)
47+
.unwrap()
48+
.into_iter()
49+
.map(|(p, _)| p)
50+
.collect()
51+
};
52+
println!("{}", (&bases(a) & &bases(b)).len() + 1);
53+
}

examples/apg4b-ex25.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// https://atcoder.jp/contests/APG4b/tasks/APG4b_bx
2+
3+
use fixedbitset::FixedBitSet;
4+
use itertools::Itertools as _;
5+
6+
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 = read!(usize);
31+
// let a = read!([usize; n]);
32+
// let m = read!(usize);
33+
// let b = read!([usize; m]);
34+
// let arg0 = read!(String);
35+
// let args = read!([usize; if arg0 == "subtract" { 1 } else { 0 }]);
36+
37+
use proconio::input;
38+
39+
input! {
40+
n: usize,
41+
a: [usize; n],
42+
m: usize,
43+
b: [usize; m],
44+
arg0: String,
45+
args: [usize; if arg0 == "subtract" { 1 } else { 0 }],
46+
}
47+
48+
let (a, b) = (a.into_iter().collect(), b.into_iter().collect());
49+
50+
print_set(&match (&*arg0, &*args) {
51+
("intersection", []) => intersection(&a, &b),
52+
("union_set", []) => union_set(&a, &b),
53+
("symmetric_diff", []) => symmetric_diff(&a, &b),
54+
("subtract", &[x]) => subtract(a, x),
55+
("increment", []) => increment(&a),
56+
("decrement", []) => decrement(&a),
57+
_ => unreachable!(),
58+
});
59+
}
60+
61+
fn print_set(set: &FixedBitSet) {
62+
println!("{}", (0..50).filter(|&i| set[i]).format(" "));
63+
}
64+
65+
fn intersection(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
66+
a & b
67+
}
68+
69+
fn union_set(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
70+
a | b
71+
}
72+
73+
fn symmetric_diff(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
74+
a ^ b
75+
}
76+
77+
fn subtract(mut a: FixedBitSet, x: usize) -> FixedBitSet {
78+
// > xは存在することが保証される。
79+
a.set(x, false);
80+
a
81+
}
82+
83+
fn increment(a: &FixedBitSet) -> FixedBitSet {
84+
a.ones().map(|x| (x + 1) % 50).collect()
85+
}
86+
87+
fn decrement(a: &FixedBitSet) -> FixedBitSet {
88+
a.ones().map(|x| (x + 49) % 50).collect()
89+
}

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