結果
問題 | No.5017 Tool-assisted Shooting |
ユーザー | ntk-ta01 |
提出日時 | 2023-07-16 18:55:21 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,583 bytes |
コンパイル時間 | 8,976 ms |
コンパイル使用メモリ | 165,004 KB |
実行使用メモリ | 24,492 KB |
スコア | 74,830 |
平均クエリ数 | 399.74 |
最終ジャッジ日時 | 2023-07-16 18:58:41 |
合計ジャッジ時間 | 12,980 ms |
ジャッジサーバーID (参考情報) |
judge9 / judge17 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 64 ms
23,388 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 67 ms
23,424 KB |
testcase_18 | AC | 67 ms
23,496 KB |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | AC | 68 ms
24,036 KB |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | AC | 71 ms
24,048 KB |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | AC | 67 ms
23,652 KB |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | AC | 68 ms
23,412 KB |
testcase_47 | RE | - |
testcase_48 | AC | 69 ms
23,376 KB |
testcase_49 | AC | 72 ms
23,820 KB |
testcase_50 | RE | - |
testcase_51 | AC | 66 ms
24,048 KB |
testcase_52 | AC | 68 ms
23,640 KB |
testcase_53 | RE | - |
testcase_54 | RE | - |
testcase_55 | RE | - |
testcase_56 | RE | - |
testcase_57 | AC | 66 ms
24,060 KB |
testcase_58 | RE | - |
testcase_59 | RE | - |
testcase_60 | RE | - |
testcase_61 | AC | 68 ms
23,520 KB |
testcase_62 | AC | 71 ms
24,036 KB |
testcase_63 | RE | - |
testcase_64 | RE | - |
testcase_65 | AC | 65 ms
23,664 KB |
testcase_66 | RE | - |
testcase_67 | RE | - |
testcase_68 | RE | - |
testcase_69 | RE | - |
testcase_70 | RE | - |
testcase_71 | RE | - |
testcase_72 | RE | - |
testcase_73 | AC | 67 ms
23,544 KB |
testcase_74 | RE | - |
testcase_75 | RE | - |
testcase_76 | RE | - |
testcase_77 | RE | - |
testcase_78 | RE | - |
testcase_79 | RE | - |
testcase_80 | RE | - |
testcase_81 | RE | - |
testcase_82 | RE | - |
testcase_83 | RE | - |
testcase_84 | RE | - |
testcase_85 | RE | - |
testcase_86 | RE | - |
testcase_87 | RE | - |
testcase_88 | RE | - |
testcase_89 | RE | - |
testcase_90 | RE | - |
testcase_91 | RE | - |
testcase_92 | AC | 65 ms
23,832 KB |
testcase_93 | RE | - |
testcase_94 | RE | - |
testcase_95 | AC | 73 ms
24,024 KB |
testcase_96 | RE | - |
testcase_97 | RE | - |
testcase_98 | RE | - |
testcase_99 | RE | - |
ソースコード
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 1..=1000 { if let Some(input) = read_input() { sim.proceed(input.es, 'S'); println!("S"); stdout().flush().unwrap(); if sim.is_defeat { break; } } else { break; } } } 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(); // eprintln!("id: {}", id); // eprintln!("initial hp: {}", enemy.hp); // eprintln!( // "hp: {}", // if enemy.hp <= enemy.dameged { // 0 // } else { // enemy.hp - enemy.dameged // } // ); // eprintln!("power: {}", enemy.power); // eprintln!("pos: ({}, {})", self.player.pos_x, h); // eprintln!(); if enemy.hp <= enemy.dameged { self.player.s += enemy.power; self.score += enemy.hp; 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, }