結果

問題 No.5 数字のブロック
ユーザー yanao
提出日時 2020-08-20 16:21:51
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 12,132 ms
コンパイル使用メモリ 378,924 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 12:49:12
合計ジャッジ時間 13,326 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `N`
  --> src/main.rs:14:9
   |
14 |     let N: u32 = nv[0].parse().unwrap(); // ブロックの数
   |         ^ help: if this is intentional, prefix it with an underscore: `_N`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> src/main.rs:13:9
   |
13 |     let mut L: u32 = lv[0].parse().unwrap(); // 箱の幅
   |         ----^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: variable `L` should have a snake case name
  --> src/main.rs:13:13
   |
13 |     let mut L: u32 = lv[0].parse().unwrap(); // 箱の幅
   |             ^ help: convert the identifier to snake case: `l`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: variable `N` should have a snake case name
  --> src/main.rs:14:9
   |
14 |     let N: u32 = nv[0].parse().unwrap(); // ブロックの数
   |         ^ help: convert the identifier to snake case: `n`

warning: variable `W` should have a snake case name
  --> src/main.rs:15:13
   |
15 |     let mut W: Vec<_> = w.trim().split(' ').collect(); // 各ブロックの幅
   |             ^ help: convert the identifier to snake case (notice the capitalization): `w`

ソースコード

diff #

fn getline() -> String{
	let mut __ret=String::new();
	std::io::stdin().read_line(&mut __ret).ok();
	return __ret;
}

fn main() {
    let l = getline();
    let n = getline();
    let w = getline();
    let lv: Vec<_> = l.trim().split(' ').collect();
    let nv: Vec<_> = n.trim().split(' ').collect();
    let mut L: u32 = lv[0].parse().unwrap(); // 箱の幅
    let N: u32 = nv[0].parse().unwrap(); // ブロックの数
    let mut W: Vec<_> = w.trim().split(' ').collect(); // 各ブロックの幅

    // 小さい順でブロックを箱に詰めていくのでソートする
    W.sort();

    let mut count: u32 = 0;
    let mut sum: u32 = 0;
    for item in W.iter() {
        let x: u32 = item.to_string().parse().unwrap();
        sum += x;
        if sum > L {
            break;
        }
        count += 1;
    }

    println!("{}", count);

}
0