結果

問題 No.5017 Tool-assisted Shooting
ユーザー tamura-uptamura-up
提出日時 2023-07-21 13:30:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 6,210 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 158,044 KB
実行使用メモリ 24,300 KB
スコア 4,129,910
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-21 13:31:03
合計ジャッジ時間 18,447 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
23,388 KB
testcase_01 AC 99 ms
24,300 KB
testcase_02 AC 98 ms
24,228 KB
testcase_03 AC 101 ms
23,628 KB
testcase_04 AC 111 ms
23,964 KB
testcase_05 AC 98 ms
24,240 KB
testcase_06 AC 99 ms
23,616 KB
testcase_07 AC 111 ms
24,012 KB
testcase_08 AC 98 ms
23,952 KB
testcase_09 AC 100 ms
23,328 KB
testcase_10 AC 100 ms
24,264 KB
testcase_11 AC 98 ms
24,000 KB
testcase_12 AC 101 ms
24,000 KB
testcase_13 AC 101 ms
24,180 KB
testcase_14 AC 101 ms
23,472 KB
testcase_15 AC 112 ms
24,216 KB
testcase_16 AC 99 ms
23,820 KB
testcase_17 AC 102 ms
23,736 KB
testcase_18 AC 100 ms
23,304 KB
testcase_19 AC 101 ms
23,628 KB
testcase_20 AC 112 ms
24,252 KB
testcase_21 AC 102 ms
23,400 KB
testcase_22 AC 98 ms
24,204 KB
testcase_23 AC 99 ms
24,204 KB
testcase_24 AC 111 ms
24,180 KB
testcase_25 AC 100 ms
23,484 KB
testcase_26 AC 100 ms
23,820 KB
testcase_27 AC 102 ms
24,012 KB
testcase_28 AC 113 ms
23,988 KB
testcase_29 AC 98 ms
23,616 KB
testcase_30 AC 99 ms
23,328 KB
testcase_31 AC 101 ms
23,352 KB
testcase_32 AC 113 ms
24,192 KB
testcase_33 AC 100 ms
23,952 KB
testcase_34 AC 100 ms
23,292 KB
testcase_35 AC 99 ms
23,316 KB
testcase_36 AC 98 ms
23,316 KB
testcase_37 AC 111 ms
23,808 KB
testcase_38 AC 99 ms
23,328 KB
testcase_39 AC 101 ms
23,616 KB
testcase_40 AC 128 ms
24,252 KB
testcase_41 AC 98 ms
23,316 KB
testcase_42 AC 100 ms
23,364 KB
testcase_43 AC 98 ms
24,252 KB
testcase_44 AC 113 ms
23,340 KB
testcase_45 AC 98 ms
23,328 KB
testcase_46 AC 99 ms
23,640 KB
testcase_47 AC 110 ms
23,316 KB
testcase_48 AC 98 ms
23,988 KB
testcase_49 AC 98 ms
23,604 KB
testcase_50 AC 118 ms
24,264 KB
testcase_51 AC 98 ms
23,304 KB
testcase_52 AC 111 ms
23,508 KB
testcase_53 AC 101 ms
23,400 KB
testcase_54 AC 131 ms
23,604 KB
testcase_55 AC 101 ms
23,508 KB
testcase_56 AC 98 ms
24,000 KB
testcase_57 AC 97 ms
23,496 KB
testcase_58 AC 99 ms
24,000 KB
testcase_59 AC 141 ms
23,388 KB
testcase_60 AC 139 ms
23,808 KB
testcase_61 AC 101 ms
23,304 KB
testcase_62 AC 100 ms
24,000 KB
testcase_63 AC 101 ms
23,820 KB
testcase_64 AC 112 ms
24,264 KB
testcase_65 AC 102 ms
23,976 KB
testcase_66 AC 100 ms
23,472 KB
testcase_67 AC 99 ms
24,228 KB
testcase_68 AC 99 ms
24,216 KB
testcase_69 AC 101 ms
23,316 KB
testcase_70 AC 100 ms
23,316 KB
testcase_71 AC 101 ms
23,304 KB
testcase_72 AC 111 ms
24,036 KB
testcase_73 AC 114 ms
23,988 KB
testcase_74 AC 98 ms
23,352 KB
testcase_75 AC 100 ms
23,352 KB
testcase_76 AC 104 ms
24,000 KB
testcase_77 AC 100 ms
23,400 KB
testcase_78 AC 111 ms
24,000 KB
testcase_79 AC 98 ms
24,000 KB
testcase_80 AC 101 ms
23,976 KB
testcase_81 AC 100 ms
23,808 KB
testcase_82 AC 99 ms
23,604 KB
testcase_83 AC 100 ms
23,304 KB
testcase_84 AC 113 ms
23,832 KB
testcase_85 AC 100 ms
23,808 KB
testcase_86 AC 128 ms
24,240 KB
testcase_87 AC 99 ms
23,808 KB
testcase_88 AC 102 ms
24,012 KB
testcase_89 AC 99 ms
23,760 KB
testcase_90 AC 99 ms
23,520 KB
testcase_91 AC 99 ms
23,988 KB
testcase_92 AC 128 ms
24,252 KB
testcase_93 AC 99 ms
23,472 KB
testcase_94 AC 100 ms
23,580 KB
testcase_95 AC 113 ms
23,304 KB
testcase_96 AC 98 ms
23,388 KB
testcase_97 AC 98 ms
23,820 KB
testcase_98 AC 98 ms
24,216 KB
testcase_99 AC 110 ms
23,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

use std::cmp::{max, min};
use std::collections::VecDeque;
use std::fs::read;
use std::io::Write;
use std::time::Instant;

const Y: usize = 60;
const X: usize = 25;
const NEG1: usize = !0;

// 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 {
    col: Vec<VecDeque<Enemy>>,
}

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

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

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

    fn attack(&mut self, x: usize, level: u32) -> u32 {
        let mut res = 0;
        if self.col[x].len() <= 0 { return 0; }

        if self.col[x][0].hp <= level {
            res = self.col[x][0].pw;
            self.col[x].pop_front();
        } else {
            self.col[x][0].hp -= level;
            eprintln!("x:{} hp:{}",x,self.col[x][0].hp);
        }
        res
    }
}


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

    while let Some(enemies) = read_input() {
        eprintln!("iter: {}, x:{}, level:{}, score:{}", iter, x, level, score);
        // if iter==861{
        //     break;
        // }
        pool.step();
        for e in enemies {
            pool.add(&e);
        }
        if let Some(e) = pool.get_first(x) {
            if e.y == 0 {
                break;
            }
        }
        // 移動
        let mut best = (-1.0, 0, x);

        for di in [!0, 1] {
            let mut ni = x;
            'outer: for step in 0..X / 2 {
                let i = ni;
                for en in &pool.col[i] {
                    if step>0 && en.y==step-1{
                        break 'outer;
                    }
                    if en.y >= step {
                        let att = level * (en.y - max(step,1) + 1) as u32;
                        if en.hp <= att {
                            let cnt = (en.hp + level - 1) / level;
                            let score = en.pw as f64 / ((max(1,step)-1) as u32 + cnt) as f64;
                            if best.0 < score {
                                best.0 = score;
                                best.1 = if step == 0 { 0 } else { di };
                                best.2 = i;
                                if iter==860 && i==18{
                                    eprintln!("attack cnt:{}, att:{}",cnt,att);
                                }
                            }
                        } else if en.y == step {
                            eprintln!("lim:{} (di:{})", i,di);
                            break 'outer;
                        }
                        break;
                    }
                }
                ni = ni.wrapping_add(di);
                ni = if ni == X { 0 } else if ni > X { X - 1 } else { ni };
            }
        }
        eprintln!("sel:{:?}",best);
        {
            let d: usize = best.1;
            let mv = match d {
                0 => "S",
                1 => "R",
                NEG1 => "L",
                _ => "S"
            };
            println!("{}", mv);

            x = x.wrapping_add(d);
            x = if x == X { 0 } else if x > X { X - 1 } else { x };
        }
        // 攻撃
        score += pool.attack(x, level);
        level = score / 100 + 1;

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

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