結果

問題 No.5017 Tool-assisted Shooting
ユーザー gobi_503gobi_503
提出日時 2023-07-16 15:23:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 6,836 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 164,928 KB
実行使用メモリ 24,408 KB
スコア 74,830
平均クエリ数 399.74
最終ジャッジ日時 2023-07-16 15:23:25
合計ジャッジ時間 9,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,364 KB
testcase_01 AC 59 ms
23,628 KB
testcase_02 AC 29 ms
24,036 KB
testcase_03 AC 28 ms
23,616 KB
testcase_04 AC 36 ms
23,376 KB
testcase_05 AC 35 ms
23,832 KB
testcase_06 AC 28 ms
23,820 KB
testcase_07 AC 37 ms
23,376 KB
testcase_08 AC 30 ms
23,844 KB
testcase_09 AC 32 ms
24,396 KB
testcase_10 AC 38 ms
23,832 KB
testcase_11 AC 30 ms
24,408 KB
testcase_12 AC 28 ms
23,820 KB
testcase_13 AC 32 ms
24,336 KB
testcase_14 AC 31 ms
23,508 KB
testcase_15 AC 29 ms
24,024 KB
testcase_16 AC 28 ms
24,348 KB
testcase_17 AC 59 ms
24,252 KB
testcase_18 AC 58 ms
23,388 KB
testcase_19 AC 31 ms
23,652 KB
testcase_20 AC 34 ms
23,400 KB
testcase_21 AC 34 ms
23,364 KB
testcase_22 AC 39 ms
24,024 KB
testcase_23 AC 28 ms
23,820 KB
testcase_24 AC 38 ms
24,360 KB
testcase_25 AC 31 ms
23,520 KB
testcase_26 AC 39 ms
23,520 KB
testcase_27 AC 59 ms
23,640 KB
testcase_28 AC 32 ms
23,952 KB
testcase_29 AC 31 ms
23,820 KB
testcase_30 AC 36 ms
24,324 KB
testcase_31 AC 27 ms
24,024 KB
testcase_32 AC 30 ms
24,312 KB
testcase_33 AC 31 ms
23,376 KB
testcase_34 AC 69 ms
24,024 KB
testcase_35 AC 29 ms
24,264 KB
testcase_36 AC 39 ms
24,024 KB
testcase_37 AC 33 ms
23,508 KB
testcase_38 AC 28 ms
23,400 KB
testcase_39 AC 58 ms
23,832 KB
testcase_40 AC 36 ms
24,264 KB
testcase_41 AC 28 ms
23,424 KB
testcase_42 AC 46 ms
23,508 KB
testcase_43 AC 46 ms
23,520 KB
testcase_44 AC 28 ms
24,336 KB
testcase_45 AC 31 ms
23,640 KB
testcase_46 AC 59 ms
24,036 KB
testcase_47 AC 33 ms
23,364 KB
testcase_48 AC 59 ms
23,412 KB
testcase_49 AC 58 ms
23,364 KB
testcase_50 AC 33 ms
23,376 KB
testcase_51 AC 59 ms
23,364 KB
testcase_52 AC 59 ms
23,820 KB
testcase_53 AC 33 ms
23,616 KB
testcase_54 AC 30 ms
23,496 KB
testcase_55 AC 42 ms
23,364 KB
testcase_56 AC 28 ms
24,012 KB
testcase_57 AC 56 ms
23,364 KB
testcase_58 AC 51 ms
24,024 KB
testcase_59 AC 30 ms
24,300 KB
testcase_60 AC 45 ms
24,000 KB
testcase_61 AC 58 ms
23,616 KB
testcase_62 AC 58 ms
24,348 KB
testcase_63 AC 31 ms
23,520 KB
testcase_64 AC 29 ms
24,036 KB
testcase_65 AC 60 ms
23,652 KB
testcase_66 AC 31 ms
23,640 KB
testcase_67 AC 29 ms
24,012 KB
testcase_68 AC 36 ms
24,000 KB
testcase_69 AC 33 ms
23,640 KB
testcase_70 AC 29 ms
23,532 KB
testcase_71 AC 37 ms
24,024 KB
testcase_72 AC 29 ms
24,324 KB
testcase_73 AC 58 ms
23,844 KB
testcase_74 AC 32 ms
23,376 KB
testcase_75 AC 30 ms
23,364 KB
testcase_76 AC 34 ms
24,384 KB
testcase_77 AC 32 ms
23,616 KB
testcase_78 AC 33 ms
24,048 KB
testcase_79 AC 41 ms
24,060 KB
testcase_80 AC 32 ms
24,312 KB
testcase_81 AC 35 ms
23,616 KB
testcase_82 AC 34 ms
23,664 KB
testcase_83 AC 32 ms
23,364 KB
testcase_84 AC 30 ms
24,324 KB
testcase_85 AC 27 ms
23,412 KB
testcase_86 AC 33 ms
24,372 KB
testcase_87 AC 29 ms
23,832 KB
testcase_88 AC 28 ms
23,364 KB
testcase_89 AC 33 ms
23,508 KB
testcase_90 AC 31 ms
24,024 KB
testcase_91 AC 28 ms
24,048 KB
testcase_92 AC 57 ms
24,240 KB
testcase_93 AC 28 ms
24,060 KB
testcase_94 AC 32 ms
24,024 KB
testcase_95 AC 60 ms
24,012 KB
testcase_96 AC 48 ms
24,012 KB
testcase_97 AC 29 ms
23,400 KB
testcase_98 AC 29 ms
23,820 KB
testcase_99 AC 31 ms
23,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
   --> Main.rs:251:13
    |
251 |         let mut ans = "S";
    |             ----^^^
    |             |
    |             help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: constant `ENEMY_NUM_MAX` is never used
   --> Main.rs:162:7
    |
162 | const ENEMY_NUM_MAX: usize = 25;
    |       ^^^^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: fields `hp`, `power`, and `score` are never read
   --> Main.rs:167:5
    |
166 | struct Enemy {
    |        ----- fields in this struct
167 |     hp: usize,    // HP (自機レベルが1ターンの与ダメージ。倒すとHP分のスコアが得られる。)
    |     ^^
168 |     power: usize, // パワー (100ごとに自機のレベルが1上がる)
    |     ^^^^^
...
171 |     score: usize, // 倒したときのスコア
    |     ^^^^^
    |
    = note: `Enemy` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis

warning: fields `me` and `level` are never read
   --> Main.rs:203:5
    |
202 | struct State {
    |        ----- fields in this struct
203 |     me: usize,    // 自機のx座標
    |     ^^
204 |     level: usize, // 自機のレベル
    |     ^^^^^

warning: 4 warnings emitted

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_imports)]
use std::io::Write;
use std::time::SystemTime;

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        #[allow(unused_imports)]
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

#[macro_export]
macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

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
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Coord {
    pub x: isize,
    pub y: isize,
}
#[allow(dead_code)]
impl Coord {
    pub fn new(p: (isize, isize)) -> Self {
        Coord { x: p.0, y: p.1 }
    }
    pub fn from_usize_pair(p: (usize, usize)) -> Self {
        Coord {
            x: p.0 as isize,
            y: p.1 as isize,
        }
    }

    pub fn in_field(&self) -> bool {
        (0 <= self.x && self.x < WIDTH as isize) && (0 <= self.y && self.y < HEIGHT as isize)
    }

    // ペアへの変換
    pub fn to_pair(&self) -> (isize, isize) {
        (self.x, self.y)
    }
    pub fn to_usize_pair(&self) -> (usize, usize) {
        (self.x as usize, self.y as usize)
    }

    // マンハッタン距離
    pub fn distance(&self, that: &Self) -> isize {
        (self.x - that.x).abs() + (self.y - that.y).abs()
    }

    pub fn mk_4dir(&self) -> Vec<Self> {
        let delta = [(-1, 0), (1, 0), (0, -1), (0, 1)];

        delta
            .iter()
            .map(|&p| self.plus(&Coord::new(p)))
            .filter(|&pos| pos.in_field())
            .collect()
    }

    pub fn com_to_delta(com: char) -> Self {
        match com {
            'U' => Coord::new((0, -1)),
            'D' => Coord::new((0, 1)),
            'L' => Coord::new((-1, 0)),
            'R' => Coord::new((1, 0)),
            _ => unreachable!(),
        }
    }

    // 四則演算
    pub fn plus(&self, that: &Self) -> Self {
        Coord::new((self.x + that.x, self.y + that.y))
    }
    pub fn minus(&self, that: &Self) -> Self {
        Coord::new((self.x - that.x, self.y - that.y))
    }

    pub fn access_matrix<'a, T>(&'a self, mat: &'a Vec<Vec<T>>) -> &'a T {
        &mat[self.y as usize][self.x as usize]
    }

    pub fn set_matrix<T>(&self, mat: &mut Vec<Vec<T>>, e: T) {
        mat[self.y as usize][self.x as usize] = e;
    }
}
// println!("{}") での表示内容
impl std::fmt::Display for Coord {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "({}, {})", self.x, self.y)?;
        Ok(())
    }
}
// println!("{:?}") での表示内容
impl std::fmt::Debug for Coord {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "({}, {})", self.x, self.y)?;
        Ok(())
    }
}

#[allow(dead_code)]
const WIDTH: usize = 25;
const HEIGHT: usize = 60;
const ENEMY_NUM_MAX: usize = 25;
const MAX_TURN: usize = 1_000;

#[derive(Clone, Copy, Debug)]
struct Enemy {
    hp: usize,    // HP (自機レベルが1ターンの与ダメージ。倒すとHP分のスコアが得られる。)
    power: usize, // パワー (100ごとに自機のレベルが1上がる)
    x: usize,     // x座標

    score: usize, // 倒したときのスコア
}
impl Enemy {
    fn new(hp: usize, power: usize, x: usize) -> Self {
        Self {
            hp,
            power,
            x,
            score: hp,
        }
    }
}

#[allow(dead_code)]
struct Input {
    n: usize,
    enemies: Vec<Enemy>,
}
impl Input {
    fn new(n: usize, sc: &mut IO<std::io::StdinLock<'_>, std::io::StdoutLock<'_>>) -> Self {
        let mut enemies = vec![];
        for _ in 0..n {
            let v = (0..3).map(|_| sc.read::<usize>()).collect::<Vec<_>>();
            let e = Enemy::new(v[0], v[1], v[2]);
            enemies.push(e);
        }

        Self { n, enemies }
    }
}

struct State {
    me: usize,    // 自機のx座標
    level: usize, // 自機のレベル
    // exp も要る。というかexpのみかも。
    field: Vec<Vec<Option<Enemy>>>,
}
impl State {
    fn new() -> Self {
        Self {
            me: 12,
            level: 1,
            field: mat![None; HEIGHT; WIDTH],
        }
    }

    // inputを反映させる更新
    fn update(&mut self, input: &Input) {
        let mut new_row = vec![None; WIDTH];
        for e in input.enemies.iter() {
            new_row[e.x] = Some(e.clone());
        }

        self.field.remove(0);
        self.field.push(new_row);
    }

    // TODO: 射撃分の更新処理も要る
}

fn main() {
    let system_time = SystemTime::now();

    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let mut st = State::new();
    for _turn in 1..=MAX_TURN {
        /* input */
        let n: isize = sc.read();
        if n == -1 {
            break;
        }

        let n = n as usize;
        let input = Input::new(n, &mut sc);

        st.update(&input);

        /* solve */
        let mut ans = "S";
        // if let Some(enemy) = st.field[1][st.me as usize] {
        //     if enemy.hp > st.level {
        //         ans = "R";
        //     }
        // }

        println!("{}", ans);

        // 解答に応じて状態を更新
    }

    eprintln!("{}ms", system_time.elapsed().unwrap().as_millis());
}
0