結果
| 問題 | 
                            No.5 数字のブロック
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-12-31 23:56:12 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,790 bytes | 
| コンパイル時間 | 13,610 ms | 
| コンパイル使用メモリ | 406,288 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-18 12:46:18 | 
| 合計ジャッジ時間 | 13,144 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 34 | 
コンパイルメッセージ
warning: field `block_num` is never read
  --> src/main.rs:15:5
   |
11 | struct InputData {
   |        --------- field in this struct
...
15 |     block_num: i32,
   |     ^^^^^^^^^
   |
   = note: `InputData` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
   = note: `#[warn(dead_code)]` on by default
            
            ソースコード
//! No.5 数字のブロック
//! https://yukicoder.me/problems/no/5
use std::io;
#[cfg(test)]
mod test;
/// 入力データ
#[derive(Debug)]
struct InputData {
    /// 大きな箱の幅
    box_width: i32,
    /// ブロックの数
    block_num: i32,
    /// 各ブロックの幅
    block_width: Vec<i32>,
}
/// エントリポイント
fn main() {
    let input = input_data();
    println!("{}", calc_in_boxes(input));
}
/// 箱に入るブロックの数を計算して返します。
fn calc_in_boxes(input: InputData) -> i32 {
    // block_widthを昇順にソート
    let mut blocks = input.block_width;
    blocks.sort();
    //
    let mut num = 0;
    let mut remaining_width = input.box_width;
    // 小さいブロックから数えて、箱の幅を超えたら終了
    for b in &blocks {
        if remaining_width >= *b {
            remaining_width -= *b;
            num += 1;
        } else {
            break;
        }
    }
    num
}
/// 標準入力から以下の形式で取得した情報を構造体に設定します。
/// ```
/// 16
/// 3
/// 10 5 7
/// ```
fn input_data() -> InputData {
    // 1行目
    let mut box_width = String::new();
    io::stdin().read_line(&mut box_width).unwrap();
    let box_width: i32 = box_width.trim().parse().unwrap();
    // 2行目
    let mut block_num = String::new();
    io::stdin().read_line(&mut block_num).unwrap();
    let block_num: i32 = block_num.trim().parse().unwrap();
    // 3行目
    let mut block_width = String::new();
    io::stdin().read_line(&mut block_width).unwrap();
    let block_width = block_width
        .trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect();
    InputData {
        box_width,
        block_num,
        block_width,
    }
}