結果

問題 No.5017 Tool-assisted Shooting
ユーザー tamura-uptamura-up
提出日時 2023-07-21 09:56:37
言語 Rust
(1.77.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 3,730 bytes
コンパイル時間 2,853 ms
コンパイル使用メモリ 162,048 KB
実行使用メモリ 24,348 KB
スコア 74,830
平均クエリ数 89.64
最終ジャッジ日時 2023-07-21 09:56:50
合計ジャッジ時間 11,525 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
23,976 KB
testcase_01 AC 32 ms
23,436 KB
testcase_02 AC 29 ms
23,292 KB
testcase_03 AC 30 ms
23,976 KB
testcase_04 AC 31 ms
23,568 KB
testcase_05 AC 31 ms
23,436 KB
testcase_06 AC 29 ms
23,940 KB
testcase_07 AC 33 ms
23,964 KB
testcase_08 AC 30 ms
23,544 KB
testcase_09 AC 30 ms
23,580 KB
testcase_10 AC 32 ms
23,592 KB
testcase_11 AC 30 ms
24,204 KB
testcase_12 AC 30 ms
23,580 KB
testcase_13 AC 30 ms
23,940 KB
testcase_14 AC 30 ms
23,604 KB
testcase_15 AC 30 ms
23,328 KB
testcase_16 AC 28 ms
23,448 KB
testcase_17 AC 34 ms
23,772 KB
testcase_18 AC 33 ms
23,352 KB
testcase_19 AC 31 ms
23,340 KB
testcase_20 AC 31 ms
23,616 KB
testcase_21 AC 30 ms
24,252 KB
testcase_22 AC 31 ms
23,976 KB
testcase_23 AC 29 ms
24,276 KB
testcase_24 AC 33 ms
23,964 KB
testcase_25 AC 29 ms
23,592 KB
testcase_26 AC 42 ms
24,180 KB
testcase_27 AC 33 ms
23,988 KB
testcase_28 AC 31 ms
24,252 KB
testcase_29 AC 31 ms
23,724 KB
testcase_30 AC 31 ms
24,000 KB
testcase_31 AC 29 ms
23,964 KB
testcase_32 AC 33 ms
23,916 KB
testcase_33 AC 31 ms
24,228 KB
testcase_34 AC 32 ms
23,976 KB
testcase_35 AC 30 ms
23,964 KB
testcase_36 AC 36 ms
23,988 KB
testcase_37 AC 30 ms
23,580 KB
testcase_38 AC 29 ms
24,264 KB
testcase_39 AC 33 ms
23,988 KB
testcase_40 AC 31 ms
24,168 KB
testcase_41 AC 29 ms
23,448 KB
testcase_42 AC 36 ms
23,556 KB
testcase_43 AC 33 ms
23,580 KB
testcase_44 AC 30 ms
23,304 KB
testcase_45 AC 29 ms
24,276 KB
testcase_46 AC 33 ms
23,568 KB
testcase_47 AC 34 ms
23,280 KB
testcase_48 AC 33 ms
23,772 KB
testcase_49 AC 33 ms
24,192 KB
testcase_50 AC 31 ms
23,976 KB
testcase_51 AC 33 ms
23,976 KB
testcase_52 AC 36 ms
23,652 KB
testcase_53 AC 31 ms
23,976 KB
testcase_54 AC 31 ms
23,964 KB
testcase_55 AC 34 ms
23,976 KB
testcase_56 AC 29 ms
23,580 KB
testcase_57 AC 34 ms
24,264 KB
testcase_58 AC 32 ms
23,724 KB
testcase_59 AC 28 ms
24,264 KB
testcase_60 AC 35 ms
23,472 KB
testcase_61 AC 34 ms
23,976 KB
testcase_62 AC 32 ms
24,228 KB
testcase_63 AC 29 ms
23,448 KB
testcase_64 AC 29 ms
23,484 KB
testcase_65 AC 32 ms
23,592 KB
testcase_66 AC 32 ms
23,448 KB
testcase_67 AC 29 ms
23,724 KB
testcase_68 AC 30 ms
23,448 KB
testcase_69 AC 30 ms
23,352 KB
testcase_70 AC 30 ms
23,796 KB
testcase_71 AC 31 ms
23,340 KB
testcase_72 AC 29 ms
23,568 KB
testcase_73 AC 34 ms
23,592 KB
testcase_74 AC 32 ms
23,712 KB
testcase_75 AC 29 ms
23,484 KB
testcase_76 AC 30 ms
23,772 KB
testcase_77 AC 31 ms
23,580 KB
testcase_78 AC 30 ms
23,964 KB
testcase_79 AC 33 ms
24,264 KB
testcase_80 AC 31 ms
23,712 KB
testcase_81 AC 31 ms
23,580 KB
testcase_82 AC 31 ms
23,940 KB
testcase_83 AC 31 ms
23,448 KB
testcase_84 AC 29 ms
23,448 KB
testcase_85 AC 29 ms
23,568 KB
testcase_86 AC 31 ms
23,700 KB
testcase_87 AC 29 ms
23,580 KB
testcase_88 AC 30 ms
23,988 KB
testcase_89 AC 30 ms
23,280 KB
testcase_90 AC 30 ms
24,348 KB
testcase_91 AC 29 ms
24,276 KB
testcase_92 AC 32 ms
24,216 KB
testcase_93 AC 28 ms
23,700 KB
testcase_94 AC 28 ms
24,264 KB
testcase_95 AC 34 ms
23,364 KB
testcase_96 AC 32 ms
23,952 KB
testcase_97 AC 28 ms
24,264 KB
testcase_98 AC 29 ms
24,252 KB
testcase_99 AC 30 ms
23,304 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
   --> Main.rs:117:9
    |
117 |     let mut x = 12;
    |         ----^
    |         |
    |         help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(non_snake_case)]

use std::collections::VecDeque;
use std::fs::read;
use std::io::Write;
use std::time::Instant;

const Y: usize = 60;
const X: usize = 25;

// src: https://yukicoder.me/submissions/892593
//
// let x = get!(i32); // 1行の i32 の入力を受け取る
// let x = get!(i32;2); // 2行の i32 の入力を受け取る
//
// tuple
// let x = get!(i32,i32,i32); // (i32, i32, i32 )のタプルを受け取る
// let x = get!(i32,i32,i32;2); // 2行 (i32, i32, i32 )のタプルを受け取る
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}


fn read_input() -> Option<Vec<(u32, u32, usize)>> {
    let n = get!(i32);
    if n < 0 {
        return None;
    }
    let mut enemies = vec![];
    for _ in 0..n {
        enemies.push(get!(u32,u32,usize));
    }

    Some(enemies)
}

#[derive (Clone, Copy, Debug)]
struct Enemy {
    hp: u32,
    pw: u32,
    y: usize,
}

struct EnemyPool {
    pool: Vec<VecDeque<Enemy>>,
}

impl EnemyPool {
    fn new() -> EnemyPool {
        EnemyPool { pool: vec![VecDeque::new(); X] }
    }

    fn add(&mut self, enemy: &(u32, u32, usize)) {
        self.pool[enemy.2].push_back(Enemy { hp: enemy.0, pw: enemy.1, y: Y - 1 });
    }

    fn step(&mut self) {
        for i in 0..self.pool.len() {
            if let Some(f) = self.pool[i].front() {
                if f.y == 0 { self.pool[i].pop_front(); }
            }
            for j in 0..self.pool[i].len() {
                self.pool[i][j].y -= 1;
            }
        }
    }
    fn get_first(&self, x: usize) -> Option<&Enemy> {
        return self.pool[x].front();
    }
}


fn main() {
    let mut iter = 0;
    let mut pool = EnemyPool::new();
    let mut x = 12;

    while let Some(enemies) = read_input() {
        pool.step();
        for e in enemies {
            pool.add(&e);
        }
        if let Some(e) = pool.get_first(x) {
            if e.y == 0 {
                break;
            }
        }
        // 移動
        println!("S");

        // 攻撃

        iter += 1;
        std::io::stdout().flush().unwrap();
        if iter >= 1000 { break; }
    }
}

pub trait SetMinMax {
    fn setmin(&mut self, v: Self) -> bool;
    fn setmax(&mut self, v: Self) -> bool;
}

impl<T> SetMinMax for T where T: PartialOrd {
    fn setmin(&mut self, v: T) -> bool {
        *self > v && {
            *self = v;
            true
        }
    }
    fn setmax(&mut self, v: T) -> bool {
        *self < v && {
            *self = v;
            true
        }
    }
}
0