結果
| 問題 |
No.9 モンスターのレベル上げ
|
| ユーザー |
hitoyozake
|
| 提出日時 | 2018-06-27 06:31:22 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 218 ms / 5,000 ms |
| コード長 | 2,726 bytes |
| コンパイル時間 | 12,899 ms |
| コンパイル使用メモリ | 401,540 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-30 23:07:29 |
| 合計ジャッジ時間 | 15,387 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
コンパイルメッセージ
warning: unused variable: `r`
--> src/main.rs:11:9
|
11 | let r = std::io::stdin().read_line(& mut buf);
| ^ help: if this is intentional, prefix it with an underscore: `_r`
|
= note: `#[warn(unused_variables)]` on by default
warning: unused variable: `integer_length`
--> src/main.rs:69:16
|
69 | let Inches(integer_length) = length;
| ^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_integer_length`
warning: unused variable: `il`
--> src/main.rs:70:9
|
70 | let il:Inches = Inches(20);
| ^^ help: if this is intentional, prefix it with an underscore: `_il`
warning: unused variable: `party`
--> src/main.rs:79:13
|
79 | let mut party: Vec<Monster> = Vec::new();
| ^^^^^ help: if this is intentional, prefix it with an underscore: `_party`
warning: variable does not need to be mutable
--> src/main.rs:79:9
|
79 | let mut party: Vec<Monster> = Vec::new();
| ----^^^^^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` on by default
warning: struct `Unit` is never constructed
--> src/main.rs:3:8
|
3 | struct Unit{
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
ソースコード
use std::collections::BinaryHeap;
struct Unit{
level: i32,
count: i32
}
fn get_line()->String{
let mut buf = String::new();
let r = std::io::stdin().read_line(& mut buf);
buf
}
use std::cmp::Ordering;
#[derive(Eq)]
struct Monster{
level: i32,
count: i32
}
impl Clone for Monster{
fn clone(&self)->Monster{
Monster{level:self.level, count:self.count}
}
}
impl PartialOrd for Monster{
fn partial_cmp(&self, other: &Monster)->Option<Ordering>{
if self.level < other.level
{
Some(Ordering::Greater)
}
else if self.level == other.level && self.count <= other.count {
Some(Ordering::Greater)
}
else{
Some(Ordering::Less)
}
}
}
impl PartialEq for Monster{
fn eq(&self, other: &Monster)->bool{
(self.level, self.count) == (other.level, other.count)
}
}
// BinaryHeapのために実装
impl Ord for Monster{
fn cmp(&self, other: &Monster)->Ordering{
(self.level, self.count).cmp(&(other.level, other.count))
//(self.level, self.count).cmp(&(other.level, other.count))
}
}
fn main() {
struct Inches(i32);
let length = Inches(10);
let Inches(integer_length) = length;
let il:Inches = Inches(20);
let mut que:BinaryHeap<Monster>= BinaryHeap::new();
let n: i32 = get_line().trim().parse::<i32>().unwrap();
let tmp = String::from(get_line().trim());
let sv:Vec<&str> = tmp.split(" ").collect();
let mut party: Vec<Monster> = Vec::new();
for i in sv{
que.push(Monster{ level:i.parse::<i32>().unwrap(), count: 0});
}
let tmp = String::from(get_line().trim());
let sv:Vec<&str> = tmp.split(" ").collect();
let mut enem_levels: Vec<i32> = Vec::new();
for i in sv{
enem_levels.push(i.parse::<i32>().unwrap()/2);
}
let mut max_count_min = 1000000;
for i in 0..n{
let mut pt = que.clone();
let mut max_count = 0;
//popされた時の値をうまくなるように調整が必要そう
for j in 0..n{
let mut selected = pt.pop().unwrap();
//println!("selected . l:{}, c:{}", selected.level, selected.count);
selected.count+=1;
let usz = ((i+j)%n) as u32;
selected.level += enem_levels[usz as usize];
max_count = std::cmp::max(max_count, selected.count);
//println!("r . l:{}, c:{}", selected.level, selected.count);
pt.push(selected);
}
max_count_min = std::cmp::min(max_count_min, max_count);
}
println!("{}", max_count_min);
}
hitoyozake