結果

問題 No.5017 Tool-assisted Shooting
ユーザー 👑 tipstar0125tipstar0125
提出日時 2023-08-01 14:37:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,230 ms / 2,000 ms
コード長 10,833 bytes
コンパイル時間 4,167 ms
コンパイル使用メモリ 167,400 KB
実行使用メモリ 24,468 KB
スコア 4,296,090
平均クエリ数 990.00
最終ジャッジ日時 2023-08-01 14:39:56
合計ジャッジ時間 123,346 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,130 ms
23,688 KB
testcase_01 AC 1,093 ms
23,628 KB
testcase_02 AC 1,203 ms
24,288 KB
testcase_03 AC 1,118 ms
23,568 KB
testcase_04 AC 1,157 ms
23,880 KB
testcase_05 AC 1,110 ms
23,340 KB
testcase_06 AC 1,116 ms
24,384 KB
testcase_07 AC 1,169 ms
23,448 KB
testcase_08 AC 1,170 ms
24,372 KB
testcase_09 AC 1,155 ms
23,340 KB
testcase_10 AC 1,139 ms
24,012 KB
testcase_11 AC 1,197 ms
23,616 KB
testcase_12 AC 1,205 ms
23,508 KB
testcase_13 AC 1,123 ms
24,348 KB
testcase_14 AC 1,116 ms
23,376 KB
testcase_15 AC 1,092 ms
23,640 KB
testcase_16 AC 1,207 ms
23,676 KB
testcase_17 AC 1,106 ms
24,348 KB
testcase_18 AC 1,112 ms
23,628 KB
testcase_19 AC 1,147 ms
23,628 KB
testcase_20 AC 1,112 ms
23,892 KB
testcase_21 AC 1,110 ms
23,424 KB
testcase_22 AC 1,197 ms
24,072 KB
testcase_23 AC 1,221 ms
23,796 KB
testcase_24 AC 1,150 ms
24,396 KB
testcase_25 AC 1,085 ms
23,364 KB
testcase_26 AC 1,171 ms
23,436 KB
testcase_27 AC 1,193 ms
23,472 KB
testcase_28 AC 1,089 ms
24,012 KB
testcase_29 AC 1,230 ms
24,024 KB
testcase_30 AC 1,222 ms
23,616 KB
testcase_31 AC 1,179 ms
23,700 KB
testcase_32 AC 1,091 ms
24,084 KB
testcase_33 AC 1,057 ms
23,472 KB
testcase_34 AC 1,201 ms
23,340 KB
testcase_35 AC 1,157 ms
23,616 KB
testcase_36 AC 1,139 ms
23,508 KB
testcase_37 AC 1,097 ms
23,472 KB
testcase_38 AC 1,067 ms
23,496 KB
testcase_39 AC 1,118 ms
23,484 KB
testcase_40 AC 1,097 ms
24,228 KB
testcase_41 AC 1,176 ms
24,468 KB
testcase_42 AC 1,063 ms
23,892 KB
testcase_43 AC 1,174 ms
23,508 KB
testcase_44 AC 1,106 ms
23,436 KB
testcase_45 AC 1,087 ms
23,436 KB
testcase_46 AC 1,100 ms
24,084 KB
testcase_47 AC 1,200 ms
23,604 KB
testcase_48 AC 1,100 ms
24,012 KB
testcase_49 AC 1,151 ms
24,276 KB
testcase_50 AC 1,109 ms
23,340 KB
testcase_51 AC 1,120 ms
24,312 KB
testcase_52 AC 1,113 ms
23,616 KB
testcase_53 AC 1,228 ms
23,436 KB
testcase_54 AC 1,115 ms
24,072 KB
testcase_55 AC 1,116 ms
23,796 KB
testcase_56 AC 1,171 ms
24,000 KB
testcase_57 AC 1,172 ms
24,084 KB
testcase_58 AC 1,134 ms
23,592 KB
testcase_59 AC 1,149 ms
23,388 KB
testcase_60 AC 1,107 ms
23,664 KB
testcase_61 AC 1,167 ms
24,012 KB
testcase_62 AC 1,203 ms
24,216 KB
testcase_63 AC 1,087 ms
23,892 KB
testcase_64 AC 1,139 ms
23,424 KB
testcase_65 AC 981 ms
24,108 KB
testcase_66 AC 1,091 ms
23,472 KB
testcase_67 AC 1,147 ms
23,592 KB
testcase_68 AC 1,128 ms
23,520 KB
testcase_69 AC 1,143 ms
23,604 KB
testcase_70 AC 1,143 ms
23,376 KB
testcase_71 AC 1,148 ms
23,508 KB
testcase_72 AC 1,160 ms
24,000 KB
testcase_73 AC 1,158 ms
23,688 KB
testcase_74 AC 1,210 ms
23,520 KB
testcase_75 AC 1,103 ms
23,472 KB
testcase_76 AC 1,148 ms
23,640 KB
testcase_77 AC 1,058 ms
24,468 KB
testcase_78 AC 1,121 ms
23,304 KB
testcase_79 AC 1,143 ms
24,348 KB
testcase_80 AC 1,106 ms
23,676 KB
testcase_81 AC 1,207 ms
23,496 KB
testcase_82 AC 1,134 ms
24,300 KB
testcase_83 AC 1,154 ms
23,508 KB
testcase_84 AC 1,107 ms
24,096 KB
testcase_85 AC 1,073 ms
23,628 KB
testcase_86 AC 1,158 ms
23,892 KB
testcase_87 AC 1,134 ms
24,000 KB
testcase_88 AC 1,113 ms
24,312 KB
testcase_89 AC 1,105 ms
24,384 KB
testcase_90 AC 1,100 ms
24,024 KB
testcase_91 AC 1,096 ms
23,700 KB
testcase_92 AC 1,176 ms
24,228 KB
testcase_93 AC 1,116 ms
24,096 KB
testcase_94 AC 1,222 ms
23,616 KB
testcase_95 AC 1,176 ms
23,712 KB
testcase_96 AC 1,131 ms
23,328 KB
testcase_97 AC 1,130 ms
23,628 KB
testcase_98 AC 1,158 ms
24,336 KB
testcase_99 AC 1,179 ms
23,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::nonminimal_bool)]
#![allow(clippy::neg_multiply)]
#![allow(clippy::type_complexity)]
#![allow(clippy::needless_range_loop)]
#![allow(dead_code)]

use std::{
    cmp::Reverse,
    collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque},
};

mod rnd {
    static mut S: usize = 0;
    static MAX: usize = 1e9 as usize;

    #[inline]
    pub fn init(seed: usize) {
        unsafe {
            if seed == 0 {
                let t = std::time::SystemTime::now()
                    .duration_since(std::time::UNIX_EPOCH)
                    .unwrap()
                    .as_secs() as usize;
                S = t
            } else {
                S = seed;
            }
        }
    }
    #[inline]
    pub fn gen() -> usize {
        unsafe {
            if S == 0 {
                init(0);
            }
            S ^= S << 7;
            S ^= S >> 9;
            S
        }
    }
    #[inline]
    pub fn gen_range(a: usize, b: usize) -> usize {
        gen() % (b - a) + a
    }
    #[inline]
    pub fn gen_bool() -> bool {
        gen() & 1 == 1
    }
    #[inline]
    pub fn gen_range_isize(a: usize) -> isize {
        let mut x = (gen() % a) as isize;
        if gen_bool() {
            x *= -1;
        }
        x
    }
    #[inline]
    pub fn gen_range_neg_wrapping(a: usize) -> usize {
        let mut x = gen() % a;
        if gen_bool() {
            x = x.wrapping_neg();
        }
        x
    }
    #[inline]
    pub fn gen_float() -> f64 {
        ((gen() % MAX) as f64) / MAX as f64
    }
}

#[derive(Debug, Clone)]
struct TimeKeeper {
    start_time: std::time::Instant,
    time_threshold: f64,
}

impl TimeKeeper {
    fn new(time_threshold: f64) -> Self {
        TimeKeeper {
            start_time: std::time::Instant::now(),
            time_threshold,
        }
    }
    #[inline]
    fn isTimeOver(&self) -> bool {
        let elapsed_time = self.start_time.elapsed().as_nanos() as f64 * 1e-9;
        #[cfg(feature = "local")]
        {
            elapsed_time * 1.5 >= self.time_threshold
        }
        #[cfg(not(feature = "local"))]
        {
            elapsed_time >= self.time_threshold
        }
    }
    #[inline]
    fn get_time(&self) -> f64 {
        let elapsed_time = self.start_time.elapsed().as_nanos() as f64 * 1e-9;
        #[cfg(feature = "local")]
        {
            elapsed_time * 1.5
        }
        #[cfg(not(feature = "local"))]
        {
            elapsed_time
        }
    }
}

const H: usize = 60;
const W: usize = 25;
const TURN: usize = 1000;
const INF: usize = 1 << 60;
const NO_ENEMY: isize = -((1 << 60) + 1);
const CANNOT_BEAT: isize = -((1 << 60) + 2);
const COLLISION: isize = -((1 << 60) + 3);
const TARGET_LEVEL: isize = 250;

#[derive(Debug, Clone)]
struct State {
    pos: (usize, usize),
    S: usize,
    score: isize,
    field: Vec<Vec<(isize, usize, isize)>>, // hp, power, init hp
    turn: usize,
}

impl State {
    fn new() -> Self {
        State {
            pos: (12, 0),
            S: 0,
            score: 0,
            field: vec![vec![(0, 0, 0); W]; H + TURN + 20],
            turn: 0,
        }
    }
    fn update_field(&mut self, n: usize) {
        let y = H + self.turn;
        for _ in 0..n {
            let v: Vec<usize> = read_vec();
            let h = v[0] as isize;
            let p = v[1];
            let x = v[2];
            self.field[y][x] = (h, p, h);
        }
    }
    fn bfs(&self, depth: usize) -> Vec<(usize, isize)> {
        // (turn, first_action)
        let (now_x, now_y) = self.pos;
        let mut dist = vec![(INF, 0); W];
        let mut Q = VecDeque::new();
        Q.push_back((now_x, 0, 2));
        dist[now_x] = (0, 0);

        while let Some((pos, t, a)) = Q.pop_front() {
            for action in -1..=1 {
                let next_x = ((W as isize + pos as isize + action) as usize) % W;
                let next_y = now_y + t + 1;
                let level = self.get_level();
                let (h, _, _) = self.field[next_y + 1][next_x];
                if t > depth || (self.field[next_y][next_x] != (0, 0, 0)) || h > level {
                    continue;
                }
                if dist[next_x].0 == INF {
                    if a == 2 {
                        dist[next_x] = (dist[pos].0 + 1, action);
                    } else {
                        dist[next_x] = (dist[pos].0 + 1, a);
                    }
                }
                if a == 2 {
                    Q.push_back((next_x, t + 1, action));
                } else {
                    Q.push_back((next_x, t + 1, a));
                }
            }
        }

        dist[now_x].0 += 1;
        dist
    }
    fn bfs2(&self, depth: usize) -> Vec<(usize, isize)> {
        // (turn, first_action)
        let (now_x, now_y) = self.pos;
        let mut dist = vec![vec![(INF, 0); W]; depth + 2];
        let mut Q = VecDeque::new();
        Q.push_back((now_x, 0, 2));
        dist[0][now_x] = (0, 0);

        while let Some((pos, t, a)) = Q.pop_front() {
            for action in -1..=1 {
                let next_x = ((W as isize + pos as isize + action) as usize) % W;
                let next_y = now_y + t + 1;
                let level = self.get_level();
                let (h, _, _) = self.field[next_y + 1][next_x];
                if t > depth || (self.field[next_y][next_x] != (0, 0, 0)) || h > level {
                    continue;
                }
                if dist[t + 1][next_x].0 == INF {
                    if a == 2 {
                        dist[t + 1][next_x] = (dist[t][pos].0 + 1, action);
                    } else {
                        dist[t + 1][next_x] = (dist[t][pos].0 + 1, a);
                    }
                }
                if a == 2 {
                    Q.push_back((next_x, t + 1, action));
                } else {
                    Q.push_back((next_x, t + 1, a));
                }
            }
        }

        dist[0][now_x].0 += 1;
        let mut d = vec![(0, 0); W];
        for j in 0..W {
            let mut turn = INF;
            let mut first_action = 0;
            for i in 0..depth {
                if dist[i][j].0 < turn {
                    turn = dist[i][j].0;
                    first_action = dist[i][j].1;
                }
            }
            d[j] = (turn, first_action);
        }
        d
    }
    fn eval_col(&self) -> isize {
        let col_turn_and_first_action = self.bfs2(9);
        let mut col_eval_result = vec![];
        let (_, now_y) = self.pos;

        'outer: for x in 0..W {
            if col_turn_and_first_action[x].0 == INF {
                continue;
            }
            let (mut turn, first_action) = col_turn_and_first_action[x];
            let mut score = 0;
            let next_y = turn + now_y;
            for y in next_y + 1..H + TURN + 10 {
                if self.field[y][x] != (0, 0, 0) {
                    let (h, p, init_hp) = self.field[y][x];
                    let dy = y - next_y;
                    let level = self.get_level();
                    let t = ((h + level - 1) / level + turn as isize - 1) as usize;
                    if dy > t {
                        let ratio = min!(1e6 as isize, 1e6 as isize * level / TARGET_LEVEL);
                        score += p as isize * (1e6 as isize - ratio) + init_hp * ratio;
                        turn = t + 1;
                    } else {
                        if score == 0 {
                            col_eval_result.push((CANNOT_BEAT, first_action));
                        } else {
                            col_eval_result.push((score / turn as isize, first_action));
                        }
                        continue 'outer;
                    }
                }
            }
            if score == 0 {
                col_eval_result.push((NO_ENEMY, first_action));
            } else {
                col_eval_result.push((score / turn as isize, first_action));
            }
        }
        col_eval_result.sort();
        col_eval_result.reverse();
        col_eval_result[0].1
    }
    fn get_level(&self) -> isize {
        (1 + self.S / 100) as isize
    }
    fn advance(&mut self, action: isize) {
        self.pos.1 += 1;
        self.pos.0 = (W as isize + action + self.pos.0 as isize) as usize % W;
        self.attack();
        self.turn += 1;
        self.output(action);
    }
    fn attack(&mut self) {
        let (now_x, now_y) = self.pos;
        let x = now_x;
        for y in now_y + 1..H + TURN + 10 {
            if self.field[y][x] != (0, 0, 0) {
                let (h, p, init_hp) = self.field[y][x];
                let level = (1 + self.S / 100) as isize;
                if h - level <= 0 {
                    self.S += p;
                    self.score += init_hp;
                    self.field[y][x] = (0, 0, 0);
                } else {
                    self.field[y][x].0 -= level;
                }
                return;
            }
        }
    }
    fn is_done(&self) -> bool {
        self.turn == TURN
    }
    fn output(&self, action: isize) {
        if action == 0 {
            println!("S");
        } else if action == -1 {
            println!("L");
        } else {
            println!("R");
        }
    }
}

#[derive(Default)]
struct Solver {}
impl Solver {
    #[allow(clippy::vec_init_then_push)]
    fn solve(&mut self) {
        let mut state = State::new();

        #[cfg(feature = "local")]
        {
            eprintln!("Local Mode");
            let _: Vec<usize> = read_vec();
        }

        while !state.is_done() {
            let N: isize = read();
            if N == -1 {
                return;
            }

            state.update_field(N as usize);
            let action = state.eval_col();
            state.advance(action);
        }
        eprintln!("Score: {}", state.score);
        eprintln!("S: {}", state.S);
    }
}

#[macro_export]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $( $y: expr ),+) => {
        std::cmp::max($x, max!($( $y ),+))
    }
}
#[macro_export]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $( $y: expr ),+) => {
        std::cmp::min($x, min!($( $y ),+))
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(128 * 1024 * 1024)
        .spawn(|| Solver::default().solve())
        .unwrap()
        .join()
        .unwrap();
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0