結果

問題 No.1286 Stone Skipping
ユーザー ikdikd
提出日時 2020-11-13 22:22:59
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,199 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 151,808 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 03:15:38
合計ジャッジ時間 2,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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.")
    }
}
0