結果
| 問題 |
No.29 パワーアップ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-28 23:12:37 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,892 bytes |
| コンパイル時間 | 11,648 ms |
| コンパイル使用メモリ | 402,476 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-24 21:09:34 |
| 合計ジャッジ時間 | 12,806 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
コンパイルメッセージ
warning: field `count` is never read
--> src/main.rs:8:5
|
6 | struct InputData {
| --------- field in this struct
7 | /// 敵を倒す回数
8 | count: 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
ソースコード
use std::collections::HashMap;
use std::io;
/// 入力データ
#[derive(Debug)]
struct InputData {
/// 敵を倒す回数
count: i32,
/// 敵を倒した時のもらえる3つのアイテムの番号
items: Vec<[i32; 3]>,
}
/// エントリポイント
fn main() {
let input = input_data();
println!("{}", power_up(input));
}
/// パワーアップする最大の回数を求めます。
fn power_up(input: InputData) -> i32 {
// アイテムを1つのVecに変換
let mut array = Vec::new();
for i in input.items {
array.push(i[0]);
array.push(i[1]);
array.push(i[2]);
}
// グルーピング
let mut map = HashMap::new();
for v in array {
*map.entry(v).or_insert(0) += 1;
}
let mut level = 0;
// 2つのアイテムでレベルアップしたあとの、残りのアイテム
let mut items = Vec::new();
for (key, val) in map {
// 「同じアイテム」を2つ
level += val / 2;
if val % 2 != 0 {
items.push(key);
}
}
// 「任意のアイテム」を4つ
level += (items.len() / 4) as i32;
level
}
/// 標準入力から文字列を取得します。
fn input_data() -> InputData {
// 1行目
let mut count = String::new();
io::stdin().read_line(&mut count).unwrap();
let count: i32 = count.trim().parse().unwrap();
// 2行目以降
let mut items = Vec::new();
for _i in 0..count {
let mut item = String::new();
io::stdin().read_line(&mut item).unwrap();
let sp: Vec<&str> = item.trim().split_whitespace().collect();
let array: [i32; 3] = [
sp[0].parse().unwrap(),
sp[1].parse().unwrap(),
sp[2].parse().unwrap(),
];
items.push(array);
}
InputData {
count,
items,
}
}