結果

問題 No.5 数字のブロック
ユーザー SarievoSarievo
提出日時 2023-05-19 20:12:23
言語 Rust
(1.77.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,576 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 154,984 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 22:54:05
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::str::FromStr`
 --> Main.rs:1:5
  |
1 | use std::str::FromStr;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: constant `DX` is never used
 --> Main.rs:3:7
  |
3 | const DX: [i32; 8] = [0, 1, 0, -1, 1, 1, -1, -1];
  |       ^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: constant `DY` is never used
 --> Main.rs:4:7
  |
4 | const DY: [i32; 8] = [1, 0, -1, 0, 1, -1, -1, 1];
  |       ^^

warning: 3 warnings emitted

ソースコード

diff #

use std::str::FromStr;

const DX: [i32; 8] = [0, 1, 0, -1, 1, 1, -1, -1];
const DY: [i32; 8] = [1, 0, -1, 0, 1, -1, -1, 1];

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let l: i64 = sc.read();
    let n: usize = sc.read();
    let mut a: Vec<i64> = sc.vec(n);
    a.sort();
    let mut now = l;
    let mut cnt = 0;
    for x in a {
        if now - x < 0 { break; }
        now -= x;
        cnt += 1;
    }
    println!("{}", cnt);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self { Self(r, std::io::BufWriter::new(w)) }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.0.by_ref().bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }.parse().ok().expect("Parse error.")
    }
    pub fn chars(&mut self) -> Vec<char> { self.read::<String>().chars().collect() }
    pub fn usize0(&mut self) -> usize { self.read::<usize>() - 1 }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
}
0