Skip to content

More tests #37

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
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
55 changes: 55 additions & 0 deletions examples/abc054-c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// https://atcoder.jp/contests/abc054/tasks/abc054_c

use petgraph::csr::Csr;
use petgraph::Undirected;

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.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;
}
});
println!("{}", ans);
}
52 changes: 52 additions & 0 deletions examples/abc084-d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// https://atcoder.jp/contests/abc084/tasks/abc084_d

use itertools_num::ItertoolsNum as _;
use primal::Sieve;

#[proconio::fastout]
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 q = read!(usize);
// let lrs = read!([(usize, usize); q]);

use proconio::input;

input! {
q: usize,
lrs: [(usize, usize); q],
}

// サンプルケースでしか試してないので嘘かもしれない。

let hi = lrs.iter().map(|&(_, r)| r).max().unwrap();
let sieve = Sieve::new(hi);
let nums = (0..=hi)
.map(|k| u32::from(sieve.is_prime(k) && sieve.is_prime((k + 1) / 2)))
.cumsum()
.collect::<Vec<u32>>();
for (l, r) in lrs {
println!("{}", nums[r] - nums[l - 1]);
}
}
53 changes: 53 additions & 0 deletions examples/abc142-d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// https://atcoder.jp/contests/abc142/tasks/abc142_d

use primal::Sieve;

use std::cmp::max;
use std::collections::HashSet;

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));

use proconio::input;

input! {
a: usize,
b: usize,
}

// サンプルケースでしか試してないので嘘かもしれない。

let sieve = Sieve::new(num_integer::sqrt(max(a, b)));
let bases = |k| -> HashSet<_> {
sieve
.factor(k)
.unwrap()
.into_iter()
.map(|(p, _)| p)
.collect()
};
println!("{}", (&bases(a) & &bases(b)).len() + 1);
}
89 changes: 89 additions & 0 deletions examples/apg4b-ex25.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// https://atcoder.jp/contests/APG4b/tasks/APG4b_bx

use fixedbitset::FixedBitSet;
use itertools::Itertools as _;

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 = read!(usize);
// let a = read!([usize; n]);
// let m = read!(usize);
// let b = read!([usize; m]);
// let arg0 = read!(String);
// let args = read!([usize; if arg0 == "subtract" { 1 } else { 0 }]);

use proconio::input;

input! {
n: usize,
a: [usize; n],
m: usize,
b: [usize; m],
arg0: String,
args: [usize; if arg0 == "subtract" { 1 } else { 0 }],
}

let (a, b) = (a.into_iter().collect(), b.into_iter().collect());

print_set(&match (&*arg0, &*args) {
("intersection", []) => intersection(&a, &b),
("union_set", []) => union_set(&a, &b),
("symmetric_diff", []) => symmetric_diff(&a, &b),
("subtract", &[x]) => subtract(a, x),
("increment", []) => increment(&a),
("decrement", []) => decrement(&a),
_ => unreachable!(),
});
}

fn print_set(set: &FixedBitSet) {
println!("{}", (0..50).filter(|&i| set[i]).format(" "));
}

fn intersection(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
a & b
}

fn union_set(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
a | b
}

fn symmetric_diff(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
a ^ b
}

fn subtract(mut a: FixedBitSet, x: usize) -> FixedBitSet {
// > xは存在することが保証される。
a.set(x, false);
a
}

fn increment(a: &FixedBitSet) -> FixedBitSet {
a.ones().map(|x| (x + 1) % 50).collect()
}

fn decrement(a: &FixedBitSet) -> FixedBitSet {
a.ones().map(|x| (x + 49) % 50).collect()
}
Loading