結果

問題 No.143 豆
ユーザー Mi_SawaMi_Sawa
提出日時 2017-02-17 01:03:31
言語 Rust
(1.72.1)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 2,224 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 151,576 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-30 16:56:10
合計ジャッジ時間 1,669 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,504 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::BufRead`
  --> Main.rs:13:13
   |
13 |         use std::io::BufRead;
   |             ^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: associated function `nl` is never used
  --> Main.rs:56:8
   |
56 |     fn nl(&mut self) -> i64 {
   |        ^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: associated function `ns` is never used
  --> Main.rs:60:8
   |
60 |     fn ns(&mut self) -> String {
   |        ^^

warning: 3 warnings emitted

ソースコード

diff #

struct Scanner<BR: std::io::BufRead> {
    buf_read: BR,
}

impl<BR: std::io::BufRead> Scanner<BR> {
    fn new(buf_read: BR) -> Scanner<BR> {
        Scanner { buf_read: buf_read }
    }

    fn read_until_f<P>(&mut self, predicate: P) -> std::io::Result<String> where
        P: std::ops::Fn(&u8) -> bool,
    {
        use std::io::BufRead;

        let mut buf = std::vec::Vec::new();
        loop {
            let (done, used) = {
                let available: &[u8] = match self.buf_read.fill_buf() {
                    Ok(b) => b,
                    Err(ref e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
                    Err(e) => return Err(e),
                };
                match available.iter().position(&predicate) {
                    Some(i) => {
                        buf.extend_from_slice(&available[..i + 1]);
                        (true, i + 1)
                    }
                    None => {
                        buf.extend_from_slice(available);
                        (false, available.len())
                    }
                }
            };
            self.buf_read.consume(used);
            if done || used == 0 {
                return match String::from_utf8(buf) {
                    Ok(s) => Ok(s),
                    Err(_) => Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "error")),
                }
            }
        }
    }
    fn next<T: std::str::FromStr>(&mut self) -> T where
        < T as std::str::FromStr >::Err: std::fmt::Debug
    {
        use ::std::str::FromStr;
        let mut with_delim = self.read_until_f(|&c| { c == b' ' || c == b'\n' }).unwrap();
        with_delim.pop();
        FromStr::from_str(with_delim.as_str()).unwrap()
    }

    fn ni(&mut self) -> i32 {
        self.next()
    }

    fn nl(&mut self) -> i64 {
        self.next()
    }

    fn ns(&mut self) -> String {
        self.next()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut scanner = Scanner::new(stdin.lock());
    let mut remain = scanner.ni() * scanner.ni();
    for _ in 0..scanner.ni() {
        remain -= scanner.ni();
    }
    if remain < 0 {
        remain = -1;
    }
    println!("{}", remain);
}
0