結果

問題 No.5017 Tool-assisted Shooting
ユーザー tishii24tishii24
提出日時 2023-08-03 23:36:51
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 6,685 bytes
コンパイル時間 3,734 ms
コンパイル使用メモリ 153,740 KB
実行使用メモリ 24,324 KB
スコア 814,726
平均クエリ数 557.83
最終ジャッジ日時 2023-08-03 23:37:06
合計ジャッジ時間 12,316 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
23,544 KB
testcase_01 AC 60 ms
24,300 KB
testcase_02 AC 61 ms
24,288 KB
testcase_03 AC 59 ms
23,544 KB
testcase_04 AC 40 ms
23,424 KB
testcase_05 AC 60 ms
23,376 KB
testcase_06 AC 61 ms
23,388 KB
testcase_07 AC 43 ms
23,628 KB
testcase_08 AC 63 ms
24,288 KB
testcase_09 AC 31 ms
23,868 KB
testcase_10 AC 31 ms
24,192 KB
testcase_11 AC 33 ms
24,036 KB
testcase_12 AC 61 ms
23,676 KB
testcase_13 AC 30 ms
23,844 KB
testcase_14 AC 33 ms
24,036 KB
testcase_15 AC 60 ms
24,048 KB
testcase_16 AC 61 ms
24,048 KB
testcase_17 AC 51 ms
24,036 KB
testcase_18 AC 61 ms
23,568 KB
testcase_19 AC 61 ms
24,276 KB
testcase_20 AC 55 ms
24,024 KB
testcase_21 AC 48 ms
23,544 KB
testcase_22 AC 45 ms
23,676 KB
testcase_23 AC 27 ms
23,388 KB
testcase_24 AC 33 ms
23,376 KB
testcase_25 AC 28 ms
23,388 KB
testcase_26 AC 28 ms
24,072 KB
testcase_27 AC 32 ms
23,676 KB
testcase_28 AC 42 ms
23,556 KB
testcase_29 AC 61 ms
23,844 KB
testcase_30 AC 59 ms
23,400 KB
testcase_31 AC 62 ms
23,376 KB
testcase_32 AC 61 ms
23,652 KB
testcase_33 AC 28 ms
24,072 KB
testcase_34 AC 61 ms
23,388 KB
testcase_35 AC 64 ms
23,556 KB
testcase_36 AC 60 ms
24,324 KB
testcase_37 AC 61 ms
23,388 KB
testcase_38 AC 37 ms
23,664 KB
testcase_39 AC 28 ms
23,676 KB
testcase_40 AC 51 ms
23,640 KB
testcase_41 AC 31 ms
23,616 KB
testcase_42 AC 60 ms
24,276 KB
testcase_43 AC 61 ms
23,856 KB
testcase_44 AC 27 ms
23,628 KB
testcase_45 AC 60 ms
24,276 KB
testcase_46 AC 60 ms
23,376 KB
testcase_47 AC 35 ms
23,616 KB
testcase_48 AC 29 ms
23,424 KB
testcase_49 AC 34 ms
23,664 KB
testcase_50 AC 31 ms
23,556 KB
testcase_51 AC 52 ms
23,652 KB
testcase_52 AC 31 ms
24,036 KB
testcase_53 AC 29 ms
24,324 KB
testcase_54 AC 61 ms
23,244 KB
testcase_55 AC 60 ms
23,556 KB
testcase_56 AC 61 ms
23,436 KB
testcase_57 AC 37 ms
23,868 KB
testcase_58 AC 35 ms
24,024 KB
testcase_59 AC 28 ms
23,652 KB
testcase_60 AC 36 ms
24,264 KB
testcase_61 AC 48 ms
23,400 KB
testcase_62 AC 32 ms
23,436 KB
testcase_63 AC 32 ms
23,568 KB
testcase_64 AC 63 ms
24,072 KB
testcase_65 AC 33 ms
23,400 KB
testcase_66 AC 62 ms
23,436 KB
testcase_67 AC 30 ms
23,448 KB
testcase_68 AC 29 ms
23,448 KB
testcase_69 AC 34 ms
23,436 KB
testcase_70 AC 31 ms
23,652 KB
testcase_71 AC 35 ms
23,688 KB
testcase_72 AC 60 ms
24,084 KB
testcase_73 AC 31 ms
23,844 KB
testcase_74 AC 60 ms
23,436 KB
testcase_75 AC 32 ms
23,640 KB
testcase_76 AC 53 ms
24,036 KB
testcase_77 AC 62 ms
24,036 KB
testcase_78 AC 50 ms
23,652 KB
testcase_79 AC 30 ms
23,628 KB
testcase_80 AC 32 ms
23,556 KB
testcase_81 AC 44 ms
23,832 KB
testcase_82 AC 60 ms
23,544 KB
testcase_83 AC 60 ms
24,240 KB
testcase_84 AC 29 ms
23,376 KB
testcase_85 AC 29 ms
23,388 KB
testcase_86 AC 36 ms
23,688 KB
testcase_87 AC 60 ms
23,400 KB
testcase_88 AC 37 ms
24,036 KB
testcase_89 AC 31 ms
23,400 KB
testcase_90 AC 34 ms
24,240 KB
testcase_91 AC 58 ms
23,436 KB
testcase_92 AC 35 ms
24,276 KB
testcase_93 AC 57 ms
23,988 KB
testcase_94 AC 28 ms
23,652 KB
testcase_95 AC 61 ms
23,436 KB
testcase_96 AC 30 ms
23,628 KB
testcase_97 AC 30 ms
23,676 KB
testcase_98 AC 61 ms
24,036 KB
testcase_99 AC 53 ms
23,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: field `initial_h` is never read
   --> Main.rs:115:5
    |
114 | struct Enemy {
    |        ----- field in this struct
115 |     initial_h: i64,
    |     ^^^^^^^^^
    |
    = note: `Enemy` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis
    = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

ソースコード

diff #

pub mod util {
    #[allow(unused_features)]
    
    pub mod rnd {
        #[allow(unused)]
        static mut S: usize = 88172645463325252;
    
        #[allow(unused)]
        #[inline]
        pub fn next() -> usize {
            unsafe {
                S = S ^ S << 7;
                S = S ^ S >> 9;
                S
            }
        }
    
        #[allow(unused)]
        #[inline]
        pub fn nextf() -> f64 {
            (next() & 4294967295) as f64 / 4294967296.
        }
    
        #[allow(unused)]
        #[inline]
        pub fn gen_range(low: usize, high: usize) -> usize {
            (next() % (high - low)) + low
        }
    
        #[allow(unused)]
        pub fn shuffle<I>(vec: &mut Vec<I>) {
            for i in 0..vec.len() {
                let j = gen_range(0, vec.len());
                vec.swap(i, j);
            }
        }
    }
    
    pub mod time {
        static mut START: f64 = -1.;
        #[allow(unused)]
        pub fn start_clock() {
            let _ = elapsed_seconds();
        }
    
        #[allow(unused)]
        #[inline]
        pub fn elapsed_seconds() -> f64 {
            let t = std::time::SystemTime::now()
                .duration_since(std::time::UNIX_EPOCH)
                .unwrap()
                .as_secs_f64();
            unsafe {
                if START < 0. {
                    START = t;
                }
                t - START
            }
        }
    }
}

use std::io::{stdout, Write};

use crate::util::*;

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<_>>()
    };
}

const H: usize = 60;
const W: usize = 25;
const T: usize = 1000;

#[derive(Clone, Default, Debug)]
struct Enemy {
    initial_h: i64,
    current_h: i64,
    p: i64,
}

fn dist(x1: usize, x2: usize) -> i64 {
    let xl = usize::min(x1, x2) as i64;
    let xr = usize::max(x1, x2) as i64;
    return i64::min(xr - xl, xl + W as i64 - xr);
}

#[derive(PartialEq, Eq)]
enum Move {
    Stay,
    Left,
    Right,
}

struct State {
    s: i64,
    cx: usize,
}

impl State {
    fn perform(&mut self, m: &Move) {
        match m {
            Move::Stay => println!("S"),
            Move::Left => {
                println!("L");
                self.cx = left_x(self.cx);
            }
            Move::Right => {
                println!("R");
                self.cx = right_x(self.cx);
            }
        };
        stdout().flush().unwrap();
    }
}

fn nearest_e_y(field: &Vec<Vec<Option<Enemy>>>, x: usize, t: usize) -> Option<usize> {
    for y in t + 1..t + H {
        if field[y][x].is_some() {
            return Some(y);
        }
    }
    None
}

fn left_x(cx: usize) -> usize {
    if cx == 0 {
        W - 1
    } else {
        cx - 1
    }
}

fn right_x(cx: usize) -> usize {
    if cx == W - 1 {
        0
    } else {
        cx + 1
    }
}

fn is_ok(field: &Vec<Vec<Option<Enemy>>>, t: usize, x: usize) -> bool {
    field[t][x].is_none() && field[t + 1][x].is_none()
}

fn move_to_x(cx: usize, to_x: usize) -> Move {
    if to_x == cx {
        Move::Stay
    } else if to_x < cx {
        if cx - to_x <= W / 2 {
            Move::Left
        } else {
            Move::Right
        }
    } else {
        if to_x - cx <= W / 2 {
            Move::Right
        } else {
            Move::Left
        }
    }
}

fn check_move(m: Move, field: &Vec<Vec<Option<Enemy>>>, t: usize, cx: usize) -> Move {
    let mut m = m;
    let nx = match m {
        Move::Stay => cx,
        Move::Left => left_x(cx),
        Move::Right => right_x(cx),
    };
    if !is_ok(field, t, nx) {
        m = if m == Move::Stay {
            Move::Left
        } else {
            Move::Stay
        };
    }
    m
}

fn attack(state: &mut State, field: &mut Vec<Vec<Option<Enemy>>>, t: usize) {
    if let Some(y) = nearest_e_y(&field, state.cx, t) {
        let e = field[y][state.cx].as_mut().unwrap();
        e.current_h -= state.s / 100 + 1;
        if e.current_h <= 0 {
            // eprintln!("destroy: p={}, h={}, x={}", e.p, e.initial_h, state.cx);
            state.s += e.p;
            field[y][state.cx] = None;
        }
    }
}

fn main() {
    time::start_clock();
    let mut field = vec![vec![None; W as usize]; (2 * H + T) as usize];

    // std::io::stdin().read_line(&mut String::new()).unwrap();

    let mut state = State { s: 0, cx: 12 };

    for t in 0..T {
        // if field[t][state.cx].is_some() { eprintln!("xxx {} {}", t, state.cx); break; }
        let n = get!(i64);
        if n == -1 {
            break;
        }

        for _ in 0..n {
            let (h, p, x) = get!(i64, i64, i64);
            field[t + H - 1][x as usize] = Some(Enemy {
                initial_h: h,
                current_h: h,
                p,
            });
        }

        let mut best_x = 0;
        let mut best_eval = 0.;
        for x in 0..W {
            if let Some(y) = nearest_e_y(&field, x, t) {
                let e = field[y][x].as_ref().unwrap();
                let turn = e.current_h / (state.s / 100 + 1) + i64::max(0, dist(x, state.cx));
                if turn >= (y - t) as i64 {
                    break;
                }
                let eval = e.p as f64 / turn as f64;
                if eval > best_eval {
                    best_eval = eval;
                    best_x = x;
                }
            }
        }

        let m = move_to_x(state.cx, best_x);
        let m = check_move(m, &field, t, state.cx);
        state.perform(&m);

        // if field[t][state.cx].is_some() { eprintln!("xxx {} {}", t, state.cx); break; }

        attack(&mut state, &mut field, t);
    }
}

0