結果

問題 No.994 ばらばらコイン
ユーザー cotton_fn_cotton_fn_
提出日時 2020-02-22 01:14:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,793 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 155,520 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 13:59:29
合計ジャッジ時間 2,153 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#![allow(unused)]

use std::io::{self, BufRead, Write};
use std::mem::{replace, swap};

pub struct Input<R> {
    src: R,
    buf: Vec<u8>,
    pos: usize,
}

impl<R: BufRead> Input<R> {
    pub fn new(src: R) -> Self {
        Self {
            src,
            buf: Vec::new(),
            pos: 0,
        }
    }

    pub fn input_bytes(&mut self) -> &[u8] {
        loop {
            self.advance_while(|b| b.is_ascii_whitespace());
            if self.pos == self.buf.len() {
                self.buf.clear();
                self.src
                    .read_until(b'\n', &mut self.buf)
                    .expect("input error");
                self.pos = 0;
            } else {
                break;
            }
        }
        let l = self.pos;
        self.advance_while(|b| !b.is_ascii_whitespace());
        &self.buf[l..self.pos]
    }

    fn advance_while(&mut self, f: impl Fn(u8) -> bool) {
        while let Some(b) = self.buf.get(self.pos) {
            if !f(*b) {
                break;
            }
            self.pos += 1;
        }
    }

    pub fn input<T: std::str::FromStr>(&mut self) -> T
    where
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        String::from_utf8_lossy(self.input_bytes())
            .parse()
            .expect("parse error")
    }
}

fn main() {
    let stdin = io::stdin();
    let mut input = Input::new(stdin.lock());
    let stdout = io::stdout();
    let mut out = io::BufWriter::new(stdout.lock());
    let stderr = io::stderr();
    let mut err = io::BufWriter::new(stderr.lock());

    let n: i32 = input.input();
    let k: i32 = input.input();
    for _ in 0..n - 1 {
        input.input_bytes();
        input.input_bytes();
    }
    writeln!(&mut out, "{}", if n >= k { k - 1 } else { -1 });
}
0