結果
問題 | No.2368 I love a square root of 2 |
ユーザー | akakimidori |
提出日時 | 2023-06-30 22:18:31 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 2,481 bytes |
コンパイル時間 | 14,783 ms |
コンパイル使用メモリ | 378,748 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 10:07:59 |
合計ジャッジ時間 | 14,273 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
5,248 KB |
testcase_01 | AC | 25 ms
5,376 KB |
testcase_02 | AC | 39 ms
5,376 KB |
testcase_03 | AC | 24 ms
5,376 KB |
testcase_04 | AC | 24 ms
5,376 KB |
testcase_05 | AC | 25 ms
5,376 KB |
testcase_06 | AC | 24 ms
5,376 KB |
testcase_07 | AC | 24 ms
5,376 KB |
testcase_08 | AC | 24 ms
5,376 KB |
testcase_09 | AC | 25 ms
5,376 KB |
testcase_10 | AC | 25 ms
5,376 KB |
testcase_11 | AC | 24 ms
5,376 KB |
testcase_12 | AC | 24 ms
5,376 KB |
testcase_13 | AC | 37 ms
5,376 KB |
testcase_14 | AC | 35 ms
5,376 KB |
testcase_15 | AC | 37 ms
5,376 KB |
testcase_16 | AC | 32 ms
5,376 KB |
testcase_17 | AC | 24 ms
5,376 KB |
testcase_18 | AC | 25 ms
5,376 KB |
testcase_19 | AC | 25 ms
5,376 KB |
testcase_20 | AC | 24 ms
5,376 KB |
testcase_21 | AC | 38 ms
5,376 KB |
testcase_22 | AC | 37 ms
5,376 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 `Map` is never used --> src/main.rs:4:6 | 4 | type Map<K, V> = BTreeMap<K, V>; | ^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias `Set` is never used --> src/main.rs:5:6 | 5 | type Set<T> = BTreeSet<T>; | ^^^ 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 main() { input! { n: i64, } let sq = 2f64.sqrt(); let mut ok = 0f64; let mut ng = 31063f64 + 96955f64 * sq; let up = ng / sq; for _ in 0..100 { let mid = (ok + ng) * 0.5; let mut cnt = 0; for j in 0..=(up as i64) { let j = j as f64; if j * sq <= mid { cnt += (mid - j * sq).floor() as i64 + 1; } } if cnt >= n { ng = mid; } else { ok = mid; } } let mut ans = (1000f64, 0f64, 0f64); for j in 0..=(up as i64) { let j = j as f64; if j * sq <= ok + 0.5 { let i = (ok - j * sq).round(); let d = (ok - j * sq - i).abs(); if d < ans.0 { ans = (d, i, j); } } } println!("{} {}", ans.1 as i64, ans.2 as i64); } // ---------- 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 ----------