結果
| 問題 |
No.1286 Stone Skipping
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2020-11-13 22:00:23 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,575 bytes |
| コンパイル時間 | 14,825 ms |
| コンパイル使用メモリ | 378,580 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-22 20:49:51 |
| 合計ジャッジ時間 | 11,981 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 1 |
ソースコード
#![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 dist(mut start: i128, bound: i32) -> i128 {
let mut ret = 0;
for _ in 0..bound {
ret += start;
start /= 2;
}
ret
}
fn main() {
let d = read::<i128>();
let mut max_bound = 0;
while d > 2i128.pow(max_bound) {
max_bound += 1;
}
debug!(max_bound);
let criterion = |mid, bound: i32| dist(mid, bound) <= d;
for bound in (1..max_bound + 1).rev() {
let (ok, _) = binary_search(1, 100000_00000_00000_001, bound as i32, criterion);
if dist(ok, bound as i32) == d {
println!("{}", ok);
return;
}
}
}
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 binary_search<F>(lb: i128, ub: i128, bound: i32, criterion: F) -> (i128, i128)
where
F: Fn(i128, i32) -> bool,
{
assert_eq!(criterion(lb, bound), true);
assert_eq!(criterion(ub, bound), false);
let mut ok = lb;
let mut ng = ub;
while ng - ok > 1 {
let mid = (ng + ok) / 2;
if criterion(mid, bound) {
ok = mid;
} else {
ng = mid;
}
}
(ok, ng)
}
fukafukatani