結果
問題 | No.2081 Make a Test Case of GCD Subset |
ユーザー | akakimidori |
提出日時 | 2022-09-25 21:48:47 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 4,884 bytes |
コンパイル時間 | 11,645 ms |
コンパイル使用メモリ | 406,468 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-01 23:28:14 |
合計ジャッジ時間 | 15,167 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
6,816 KB |
testcase_01 | AC | 13 ms
6,816 KB |
testcase_02 | AC | 13 ms
6,940 KB |
testcase_03 | AC | 13 ms
6,940 KB |
testcase_04 | AC | 12 ms
6,940 KB |
testcase_05 | AC | 12 ms
6,940 KB |
testcase_06 | AC | 12 ms
6,940 KB |
testcase_07 | AC | 13 ms
6,940 KB |
testcase_08 | AC | 12 ms
6,944 KB |
testcase_09 | AC | 12 ms
6,940 KB |
testcase_10 | AC | 13 ms
6,940 KB |
testcase_11 | AC | 13 ms
6,940 KB |
testcase_12 | AC | 13 ms
6,944 KB |
testcase_13 | AC | 12 ms
6,940 KB |
testcase_14 | AC | 12 ms
6,944 KB |
testcase_15 | AC | 12 ms
6,940 KB |
testcase_16 | AC | 13 ms
6,940 KB |
testcase_17 | AC | 13 ms
6,940 KB |
testcase_18 | AC | 13 ms
6,940 KB |
testcase_19 | AC | 13 ms
6,940 KB |
testcase_20 | AC | 12 ms
6,944 KB |
testcase_21 | AC | 11 ms
6,944 KB |
testcase_22 | AC | 13 ms
6,944 KB |
testcase_23 | AC | 12 ms
6,940 KB |
testcase_24 | AC | 12 ms
6,940 KB |
testcase_25 | AC | 13 ms
6,940 KB |
testcase_26 | AC | 13 ms
6,940 KB |
testcase_27 | AC | 13 ms
6,940 KB |
コンパイルメッセージ
warning: unused import: `std::io::Write` --> src/main.rs:1:5 | 1 | use std::io::Write; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: type alias `Set` is never used --> src/main.rs:5:6 | 5 | type Set<T> = BTreeSet<T>; | ^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias `Deque` is never used --> src/main.rs:6:6 | 6 | type Deque<T> = VecDeque<T>; | ^^^^^
ソースコード
use std::io::Write; use std::collections::*; type Map<K, V> = BTreeMap<K, V>; type Set<T> = BTreeSet<T>; type Deque<T> = VecDeque<T>; fn run() { input! { m: usize, } let n = 100000; let mut factor = vec![n; n + 1]; enumerate_prime(n, |p| { for i in 1..=(n / p) { factor[i * p] = factor[i * p].min(p); } }); let mut map = Map::new(); for i in 2..=n { let sp = factor[i]; let mut x = i; while x % sp == 0 { x /= sp; } if x == 1 { map.entry(sp).or_insert(vec![]).push((i, 0)); continue; } let lp = factor[x]; while x % lp == 0 { x /= lp; } if x == 1 { map.entry(sp).or_insert(vec![]).push((i, lp)); } } let mut used = vec![false; n + 1]; let mut ans = vec![1]; let mut m = m; for (prime, mut a) in map { if used[prime] || m == 0 { continue; } used[prime] = true; a.sort_by_key(|p| !p.1); let zero = a.iter().filter(|a| a.1 == 0).count(); a.rotate_right(zero); let mut b = vec![]; for (i, k) in a { if (1usize << (b.len() + 1)) - 1 <= m && (k == 0 || !used[k]) { b.push((i, k)); } } m -= (1 << b.len()) - 1; for (i, k) in b { if k > 0 { used[k] = true; } ans.push(i); } } assert!(m == 0); println!("{}", ans.len()); use util::*; println!("{}", ans.iter().join(" ")); } fn main() { run(); } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- // ---------- begin enumerate prime ---------- fn enumerate_prime<F>(n: usize, mut f: F) where F: FnMut(usize), { assert!(1 <= n && n <= 5 * 10usize.pow(8)); let batch = (n as f64).sqrt().ceil() as usize; let mut is_prime = vec![true; batch + 1]; for i in (2..).take_while(|p| p * p <= batch) { if is_prime[i] { let mut j = i * i; while let Some(p) = is_prime.get_mut(j) { *p = false; j += i; } } } let mut prime = vec![]; for (i, p) in is_prime.iter().enumerate().skip(2) { if *p && i <= n { f(i); prime.push(i); } } let mut l = batch + 1; while l <= n { let r = std::cmp::min(l + batch, n + 1); is_prime.clear(); is_prime.resize(r - l, true); for &p in prime.iter() { let mut j = (l + p - 1) / p * p - l; while let Some(is_prime) = is_prime.get_mut(j) { *is_prime = false; j += p; } } for (i, _) in is_prime.iter().enumerate().filter(|p| *p.1) { f(i + l); } l += batch; } } // ---------- end enumerate prime ---------- mod util { pub trait Join { fn join(self, sep: &str) -> String; } impl<T, I> Join for I where I: Iterator<Item = T>, T: std::fmt::Display, { fn join(self, sep: &str) -> String { let mut s = String::new(); use std::fmt::*; for (i, v) in self.enumerate() { if i > 0 { write!(&mut s, "{}", sep).ok(); } write!(&mut s, "{}", v).ok(); } s } } }