結果
問題 | No.1514 Squared Matching |
ユーザー | fukafukatani |
提出日時 | 2021-05-21 22:43:40 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 2,039 ms / 4,000 ms |
コード長 | 2,071 bytes |
コンパイル時間 | 641 ms |
コンパイル使用メモリ | 171,828 KB |
実行使用メモリ | 392,580 KB |
最終ジャッジ日時 | 2024-04-18 16:11:17 |
合計ジャッジ時間 | 35,566 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2,032 ms
392,576 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 27 ms
7,808 KB |
testcase_07 | AC | 370 ms
76,528 KB |
testcase_08 | AC | 1,947 ms
378,240 KB |
testcase_09 | AC | 1,699 ms
330,980 KB |
testcase_10 | AC | 1,848 ms
358,400 KB |
testcase_11 | AC | 1,926 ms
373,356 KB |
testcase_12 | AC | 1,973 ms
383,632 KB |
testcase_13 | AC | 2,014 ms
388,736 KB |
testcase_14 | AC | 2,016 ms
390,784 KB |
testcase_15 | AC | 2,037 ms
391,808 KB |
testcase_16 | AC | 2,030 ms
392,192 KB |
testcase_17 | AC | 2,027 ms
392,448 KB |
testcase_18 | AC | 2,031 ms
392,580 KB |
testcase_19 | AC | 2,031 ms
392,536 KB |
testcase_20 | AC | 2,033 ms
392,448 KB |
testcase_21 | AC | 2,039 ms
392,548 KB |
testcase_22 | AC | 388 ms
79,980 KB |
testcase_23 | AC | 793 ms
158,080 KB |
testcase_24 | AC | 1,210 ms
236,288 KB |
testcase_25 | AC | 1,633 ms
314,240 KB |
コンパイルメッセージ
warning: function `read_vec` is never used --> main.rs:88:4 | 88 | fn read_vec<T: std::str::FromStr>() -> Vec<T> { | ^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: 1 warning emitted
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::<usize>(); let mut squares = vec![]; for i in 1.. { if i * i > n { break; } squares.push(i as i64 * i as i64); } squares.reverse(); let mut numbers = vec![0i64; n + 1]; for i in 1..=n { numbers[i] = i as i64; } for &sq in &squares { let mut cur = sq; while cur <= n as i64 { if numbers[cur as usize] % sq == 0 { numbers[cur as usize] /= sq; } cur += sq } } if n < 50 { debug!(numbers); } squares.reverse(); let criterion = |x, mid| { if mid == squares.len() { return false; } x * squares[mid] <= n as i64 }; let mut ans = 0; for i in 1..=n { let (ok, _) = binary_search(0, squares.len(), |mid: usize| criterion(numbers[i], mid)); ans += ok as i64 + 1; } println!("{}", ans); } type Input = usize; fn binary_search<F>(lb: Input, ub: Input, criterion: F) -> (Input, Input) where F: Fn(Input) -> bool, { assert_eq!(criterion(lb), true); assert_eq!(criterion(ub), false); let mut ok = lb; let mut ng = ub; while ng - ok > 1 { let mid = (ng + ok) / 2; if criterion(mid) { ok = mid; } else { ng = mid; } } (ok, ng) } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }