結果
問題 |
No.1286 Stone Skipping
|
ユーザー |
![]() |
提出日時 | 2020-11-13 22:22:59 |
言語 | Rust (1.83.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,199 bytes |
コンパイル時間 | 13,243 ms |
コンパイル使用メモリ | 400,288 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-22 21:14:04 |
合計ジャッジ時間 | 15,356 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 RE * 2 |
ソースコード
fn main() { let stdin = std::io::stdin(); let mut rd = ProconReader::new(stdin.lock()); let d: i64 = rd.get(); for y in ((d / 2 - 100000)..=(d / 2 + 100000)).filter(|&y| 1 <= y && y <= d) { if (0..60) .scan((0, y), |(s, x), _| { *s += *x; *x /= 2; Some((*s, *x)) }) .any(|(s, _)| s == d) { println!("{}", y); return; } } unreachable!(); } pub struct ProconReader<R: std::io::Read> { reader: R, } impl<R: std::io::Read> ProconReader<R> { pub fn new(reader: R) -> Self { Self { reader } } pub fn get<T: std::str::FromStr>(&mut self) -> T { use std::io::Read; let buf = self .reader .by_ref() .bytes() .map(|b| b.unwrap()) .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r') .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r') .collect::<Vec<_>>(); std::str::from_utf8(&buf) .unwrap() .parse() .ok() .expect("Parse Error.") } }