結果
問題 | No.5017 Tool-assisted Shooting |
ユーザー | ntk-ta01 |
提出日時 | 2023-07-16 18:35:32 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,074 bytes |
コンパイル時間 | 1,698 ms |
コンパイル使用メモリ | 164,208 KB |
実行使用メモリ | 32,784 KB |
スコア | 0 |
最終ジャッジ日時 | 2023-07-16 18:35:42 |
合計ジャッジ時間 | 8,268 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
testcase_63 | -- | - |
testcase_64 | -- | - |
testcase_65 | -- | - |
testcase_66 | -- | - |
testcase_67 | -- | - |
testcase_68 | -- | - |
testcase_69 | -- | - |
testcase_70 | -- | - |
testcase_71 | -- | - |
testcase_72 | -- | - |
testcase_73 | -- | - |
testcase_74 | -- | - |
testcase_75 | -- | - |
testcase_76 | -- | - |
testcase_77 | -- | - |
testcase_78 | -- | - |
testcase_79 | -- | - |
testcase_80 | -- | - |
testcase_81 | -- | - |
testcase_82 | -- | - |
testcase_83 | -- | - |
testcase_84 | -- | - |
testcase_85 | -- | - |
testcase_86 | -- | - |
testcase_87 | -- | - |
testcase_88 | -- | - |
testcase_89 | -- | - |
testcase_90 | -- | - |
testcase_91 | -- | - |
testcase_92 | -- | - |
testcase_93 | -- | - |
testcase_94 | -- | - |
testcase_95 | -- | - |
testcase_96 | -- | - |
testcase_97 | -- | - |
testcase_98 | -- | - |
testcase_99 | -- | - |
ソースコード
use std::{ collections::HashMap, io::{stdin, stdout, Write}, }; const H: usize = 60; const W: usize = 25; // type Output = Vec<char>; fn main() { let mut sim = Sim::new(); for _ in 0..1000 { if let Some(input) = read_input() { if !sim.is_defeat { sim.proceed(input.es, 'S'); println!("S"); stdout().flush().unwrap(); } } else { break; } } eprintln!("score = {}", sim.score); } fn read_input() -> Option<Input> { let mut n = String::new(); stdin().read_line(&mut n).unwrap(); if n == "-1" { return None; } let n = n.trim().parse::<usize>().unwrap(); let mut es = vec![]; for _ in 0..n { let mut line = String::new(); stdin().read_line(&mut line).unwrap(); let mut tokens = line.split_whitespace(); let h = tokens.next().unwrap().parse::<i64>().unwrap(); let p = tokens.next().unwrap().parse::<i64>().unwrap(); let x = tokens.next().unwrap().parse::<usize>().unwrap(); es.push((h, p, x)); } Some(Input { n, es }) } #[allow(dead_code)] #[derive(Debug)] struct Input { n: usize, es: Vec<(i64, i64, usize)>, } #[derive(Debug, Clone, Copy)] pub struct Player { s: i64, pos_x: usize, } impl Player { pub fn new() -> Self { Player { s: 0, pos_x: 12 } } pub fn level(&self) -> i64 { 1 + self.s / 100 } } impl Default for Player { fn default() -> Self { Self::new() } } struct Enemy { hp: i64, dameged: i64, power: i64, } impl Enemy { pub fn new(hp: i64, power: i64) -> Self { Self { hp, dameged: 0, power, } } } pub struct Sim { board: Vec<Vec<Square>>, player: Player, enemies: HashMap<usize, Enemy>, score: i64, is_defeat: bool, } impl Sim { pub fn new() -> Self { let mut board = vec![vec![Square::EMPTY; W]; H]; board[0][12] = Square::PLAYER; let player = Player::new(); let enemies = HashMap::new(); Self { board, player, enemies, score: 0, is_defeat: false, } } pub fn proceed(&mut self, es: Vec<(i64, i64, usize)>, command: char) { // 全enemyが一段下に for h in 0..H { for w in 0..W { if let Square::ENEMY { id: _ } = self.board[h][w] { if h != 0 { if Square::PLAYER == self.board[h - 1][w] { self.is_defeat = true; } self.board[h - 1][w] = self.board[h][w]; } self.board[h][w] = Square::EMPTY; } } } // 新たなenemyが出現 for (h, p, x) in es { let id = self.enemies.len() + 1; self.board[H - 1][x] = Square::ENEMY { id }; self.enemies.insert(id, Enemy::new(h, p)); } // playerが移動 match command { 'L' => { let prev_x = self.player.pos_x; let next_x = (self.player.pos_x + W - 1) % W; if let Square::ENEMY { id: _ } = self.board[0][next_x] { self.is_defeat = true; } else { self.board[0][next_x] = self.board[0][prev_x]; } self.board[0][prev_x] = Square::EMPTY; self.player.pos_x = next_x; } 'R' => { let prev_x = self.player.pos_x; let next_x = (self.player.pos_x + W + 1) % W; self.player.pos_x = next_x; if let Square::ENEMY { id: _ } = self.board[0][next_x] { self.is_defeat = true; } else { self.board[0][next_x] = self.board[0][prev_x]; } self.board[0][prev_x] = Square::EMPTY; self.player.pos_x = next_x; } 'S' => {} _ => unreachable!(), } // playerによる攻撃 if !self.is_defeat { for h in 1..H { if let Square::ENEMY { id } = self.board[h][self.player.pos_x] { let enemy = self.enemies.get_mut(&id).unwrap(); enemy.dameged += self.player.level(); if enemy.hp <= enemy.dameged { self.player.s += enemy.power; self.score += enemy.hp; self.enemies.remove(&id); self.board[h][self.player.pos_x] = Square::EMPTY; } break; } } } } } impl Default for Sim { fn default() -> Self { Self::new() } } #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] pub enum Square { PLAYER, ENEMY { id: usize }, EMPTY, }