結果

問題 No.1286 Stone Skipping
ユーザー ikdikd
提出日時 2020-11-13 22:33:35
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,310 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 146,924 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 03:33:34
合計ジャッジ時間 3,307 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 7 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 6 ms
4,376 KB
testcase_27 AC 6 ms
4,376 KB
testcase_28 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let d: i64 = rd.get();
    let mut e = d;
    while e > 0 {
        for y in ((e / 2 - 100000)..=(e / 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;
            }
        }
        e /= 2;
    }
    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.")
    }
}
0