結果

問題 No.5017 Tool-assisted Shooting
ユーザー jabeejabee
提出日時 2023-07-21 12:54:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 17,271 bytes
コンパイル時間 7,949 ms
コンパイル使用メモリ 289,308 KB
実行使用メモリ 35,060 KB
スコア 3,589
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-21 12:54:53
合計ジャッジ時間 26,412 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
34,480 KB
testcase_01 AC 148 ms
34,120 KB
testcase_02 AC 144 ms
34,420 KB
testcase_03 AC 147 ms
34,956 KB
testcase_04 AC 146 ms
34,980 KB
testcase_05 AC 145 ms
34,152 KB
testcase_06 AC 163 ms
34,680 KB
testcase_07 AC 145 ms
34,316 KB
testcase_08 AC 145 ms
34,244 KB
testcase_09 AC 153 ms
34,740 KB
testcase_10 AC 145 ms
34,340 KB
testcase_11 AC 150 ms
34,204 KB
testcase_12 AC 147 ms
34,892 KB
testcase_13 AC 144 ms
34,560 KB
testcase_14 AC 151 ms
34,916 KB
testcase_15 AC 142 ms
34,204 KB
testcase_16 AC 143 ms
34,340 KB
testcase_17 AC 147 ms
34,320 KB
testcase_18 AC 144 ms
34,424 KB
testcase_19 AC 144 ms
34,720 KB
testcase_20 AC 146 ms
34,364 KB
testcase_21 AC 146 ms
34,028 KB
testcase_22 AC 148 ms
34,416 KB
testcase_23 AC 144 ms
34,208 KB
testcase_24 AC 144 ms
34,504 KB
testcase_25 AC 146 ms
34,184 KB
testcase_26 AC 146 ms
34,220 KB
testcase_27 AC 142 ms
35,000 KB
testcase_28 AC 144 ms
34,324 KB
testcase_29 AC 143 ms
34,040 KB
testcase_30 AC 143 ms
34,492 KB
testcase_31 AC 145 ms
34,672 KB
testcase_32 AC 145 ms
34,828 KB
testcase_33 AC 147 ms
34,268 KB
testcase_34 AC 143 ms
34,452 KB
testcase_35 AC 147 ms
34,844 KB
testcase_36 AC 143 ms
35,060 KB
testcase_37 AC 147 ms
34,480 KB
testcase_38 AC 151 ms
34,676 KB
testcase_39 AC 146 ms
34,656 KB
testcase_40 AC 147 ms
34,932 KB
testcase_41 AC 144 ms
34,600 KB
testcase_42 AC 145 ms
34,356 KB
testcase_43 AC 146 ms
34,188 KB
testcase_44 AC 146 ms
34,792 KB
testcase_45 AC 146 ms
34,612 KB
testcase_46 AC 152 ms
34,600 KB
testcase_47 AC 151 ms
34,608 KB
testcase_48 AC 144 ms
34,240 KB
testcase_49 AC 143 ms
34,380 KB
testcase_50 AC 145 ms
34,808 KB
testcase_51 AC 153 ms
34,488 KB
testcase_52 AC 145 ms
34,128 KB
testcase_53 AC 147 ms
34,616 KB
testcase_54 AC 144 ms
34,424 KB
testcase_55 AC 145 ms
34,716 KB
testcase_56 AC 149 ms
34,316 KB
testcase_57 AC 144 ms
34,328 KB
testcase_58 AC 145 ms
34,708 KB
testcase_59 AC 164 ms
34,964 KB
testcase_60 AC 145 ms
34,704 KB
testcase_61 AC 145 ms
34,472 KB
testcase_62 AC 144 ms
34,420 KB
testcase_63 AC 144 ms
34,336 KB
testcase_64 AC 145 ms
34,432 KB
testcase_65 AC 145 ms
34,512 KB
testcase_66 AC 150 ms
34,580 KB
testcase_67 AC 143 ms
34,032 KB
testcase_68 AC 148 ms
34,416 KB
testcase_69 AC 144 ms
34,472 KB
testcase_70 AC 144 ms
34,788 KB
testcase_71 AC 142 ms
34,452 KB
testcase_72 AC 148 ms
34,332 KB
testcase_73 AC 155 ms
34,420 KB
testcase_74 AC 143 ms
34,628 KB
testcase_75 AC 147 ms
34,492 KB
testcase_76 AC 155 ms
34,252 KB
testcase_77 AC 147 ms
33,936 KB
testcase_78 AC 146 ms
34,748 KB
testcase_79 AC 148 ms
34,540 KB
testcase_80 AC 146 ms
34,712 KB
testcase_81 AC 148 ms
34,176 KB
testcase_82 AC 146 ms
34,096 KB
testcase_83 AC 145 ms
34,552 KB
testcase_84 AC 148 ms
34,288 KB
testcase_85 AC 151 ms
34,724 KB
testcase_86 AC 150 ms
34,212 KB
testcase_87 AC 144 ms
34,892 KB
testcase_88 AC 144 ms
34,468 KB
testcase_89 AC 170 ms
34,608 KB
testcase_90 AC 155 ms
34,276 KB
testcase_91 AC 156 ms
34,384 KB
testcase_92 AC 146 ms
34,688 KB
testcase_93 AC 150 ms
34,336 KB
testcase_94 AC 149 ms
34,604 KB
testcase_95 AC 145 ms
34,252 KB
testcase_96 AC 147 ms
34,344 KB
testcase_97 AC 145 ms
34,456 KB
testcase_98 AC 145 ms
34,600 KB
testcase_99 AC 153 ms
34,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <atcoder/all>
#include <atcoder/dsu>
#include <atcoder/segtree>
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <atcoder/scc>
#include <chrono>
#include <random>
#include <cassert>
#ifndef templete
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
 
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
using namespace atcoder;
//using atmint = modint998244353;
using atmint = modint;
using Graph = vector<vector<int>>;
using P = pair<long long,long long>;
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
 
//---------------------------------------------------------------------------------------------------
 
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
template<typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac;
    Comb(){fac.resize(FAC_MAX,1);ifac.resize(FAC_MAX,1);rep(i,1,FAC_MAX)fac[i]=fac[i-1]*i;
        ifac[FAC_MAX-1]=T(1)/fac[FAC_MAX-1];rrep(i,FAC_MAX-2,1)ifac[i]=ifac[i+1]*T(i+1);}
    T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; }
    T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; }
    T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0;
        return aCb(n + k - 1, k); } // nHk = (n+k-1)Ck : n is separator
    T pairCombination(int n) {if(n%2==1)return T(0);return fac[n]*ifac[n/2]/(T(2)^(n/2));}
    // combination of paris for n com.aCb(h+w-2,h-1);
}; 
//typedef ModInt<1000000007> mint;
typedef ModInt<998244353> mint; 
//typedef ModInt<1000000000> mint; 
Comb<mint, 2010101> com;
//vector dp(n+1,vector(n+1,vector<ll>(n+1,0)));
//vector dp(n+1,vector<ll>(n+1,0));
  std::random_device seed_gen;
  std::mt19937 engine(seed_gen());
string ye = "Yes"; string no = "No"; string draw = "Draw";
 
#endif // templete
//---------------------------------------------------------------------------------------------------
// 座標を保持する
struct Coord
{
    int h_;
    int sh_;
    int p_;
    Coord(const int h = 0,const int p = 0) : h_(h), sh_(h), p_(p) {}
};

// 時間を管理するクラス
class TimeKeeper
{
private:
    std::chrono::high_resolution_clock::time_point start_time_;
    int64_t time_threshold_;

public:
    // 時間制限をミリ秒単位で指定してインスタンスをつくる。
    TimeKeeper(const int64_t &time_threshold)
        : start_time_(std::chrono::high_resolution_clock::now()),
          time_threshold_(time_threshold)
    {
    }

    // インスタンス生成した時から指定した時間制限を超過したか判定する。
    bool isTimeOver() const
    {
        auto diff = std::chrono::high_resolution_clock::now() - this->start_time_;
        return std::chrono::duration_cast<std::chrono::milliseconds>(diff).count() >= time_threshold_;
    }
};

std::mt19937 mt_for_action(0);                // 行動選択用の乱数生成器を初期化
using ScoreType = int64_t;                    // ゲームの評価スコアの型を決めておく。
constexpr const ScoreType INF = 1000000000LL; // あり得ないぐらい大きなスコアの例を用意しておく

constexpr const int H = 60;   // 迷路の高さ
constexpr const int W = 25;   // 迷路の幅
constexpr int END_TURN = 1000; // ゲーム終了ターン
vector<ll>l_actions;
// 一人ゲームの例
// 1ターンに上下左右四方向のいずれかに1マスずつ進む。
// 床にあるポイントを踏むと自身のスコアとなり、床のポイントが消える。
// END_TURNの時点のスコアを高くすることが目的
class State
{
private:
    static constexpr const int dx[4] = {1, -1, 0, 0}; // 右、左、下、上への移動方向のx成分
    static constexpr const int dy[4] = {0, 0, 1, -1}; // 右、左、下、上への移動方向のy成分

public:
//    Coord board[W][H] = {};
    vector<vector<Coord>>board;
    int self_x = 12;
    int self_y = 0;
    Coord character_ = Coord();
    int game_score_ = 0;            // ゲーム上で実際に得たスコア
    ScoreType evaluated_score_ = 0; // 探索上で評価したスコア
    char first_action_ = 'S';         // 探索木のルートノードで最初に選択した行動
    int level = 1;
    int damage = 0;
    int update_turn = 0;
    string str = "";
    int input_n = 0;
    int live = 0;
    State() {}
    State(ll make) {
      live = 1;
      board.resize(W);
      rep(i,0,W)board[i].resize(H);
    }
    int turn_ = 0;          // 現在のターン
  
    bool check_death(){
        bool res = false;
        if(board[self_x][self_y].h_ >= 1)res = true;
        return res;
    }

    void deki_move(){
        rep(y,0,H-1)rep(x,0,W){
            board[x][y] = board[x][y+1];
        }
        rep(x,0,W){
            board[x][H-1].h_ = 0;
            board[x][H-1].p_ = 0;
        }
        if(check_death())live = 0;
    }

    void atack(){
        if(live == 0)return;
        rep(y,1,H-1){
            if(board[self_x][y].h_ >= 1){
                ll orih_ = board[self_x][y].h_;
                board[self_x][y].h_ -= (1 + level / 100);
                chmax(board[self_x][y].h_,0);
                ll nxth_ = board[self_x][y].h_;
                damage += orih_ - nxth_;
                update_turn = turn_;
                if(board[self_x][y].h_ <= 0){
                    level += board[self_x][y].p_;
                    game_score_ += board[self_x][y].sh_;
                }
                break;
            }
        }
    }
    void input(int real){
        deki_move();
        if(check_death())live = 0;
      if(real == 1){
        ll n;
            cin >> n;
            input_n = n;
            if(n == -1)return;
            rep(i,0,n){
                ll h,p,x;
                cin >> h >> p >> x;
                board[x][H-1].sh_ = h;
                board[x][H-1].h_ = h;
                board[x][H-1].p_ = p; 
            }
      }
    }

    // [どのゲームでも実装する] : ゲームの終了判定
    bool isDone()
    {
        bool res = false;
        //if(this->turn_ >= END_TURN)res = true;
        if(check_death())res = true;
        if(input_n == -1)res = true;
        return res;
    }
    // [どのゲームでも実装する] : 探索用の盤面評価をする
    void evaluateScore()
    {
        this->evaluated_score_ = this->game_score_; // 簡単のため、まずはゲームスコアをそのまま盤面の評価とする
    }

    void advance(const char action)
    {
        if(action == 'R' && self_x != W - 1)self_x++;
        if(action == 'L' && self_x != 0)self_x--;
        if(check_death())live = 0;
        atack();
        this->turn_++;
        
    }
    /*
    // [どのゲームでも実装する] : 指定したactionでゲームを1ターン進める
    void advance(const char action, int real)
    {
        rep(y,0,H-1)rep(x,0,W){
            board[x][y] = board[x][y+1];
        }
        rep(x,0,W){
            board[x][H-1].h_ = 0;
            board[x][H-1].p_ = 0;
        }
        str += action;
        if(real == 1){
          //  cerr << "str add" << action << endl;
            ll n;
            cin >> n;
            input_n = n;
            if(input_n == -1){
                this->turn_++;
                return;
            }
            rep(i,0,n){
                ll h,p,x;
                cin >> h >> p >> x;
                board[x][H-1].h_ = h;
                board[x][H-1].p_ = p; 
            }
        }else{
        //    cerr << "kari advance" << action << endl;
        }
        if(action == 'R')self_x++;
        if(action == 'L')self_x--;
        rep(y,1,H-1){
            if(board[self_x][y].h_ >= 1){
                board[self_x][y].h_ -= (1 + level / 100);
                if(board[self_x][y].h_ <= 0){
                    level += board[self_x][y].p_;
                    game_score_ += board[self_x][y].sh_;
                }
                break;
            }
        }
            this->turn_++;
    }
    */

    // [どのゲームでも実装する] : 現在の状況でプレイヤーが可能な行動を全て取得する
    std::vector<char> legalActions() const
    {
        std::vector<char> actions = {};
        if(self_x != 0)actions.push_back('L');
        actions.push_back('S');
        if(self_x != W-1)actions.push_back('R');
        return actions;
    }

};

// [どのゲームでも実装する] : 探索時のソート用に評価を比較する
bool operator<(const State &state_1, const State &state_2)
{

    if(state_1.game_score_ != state_2.game_score_)
    {
      return state_1.game_score_ < state_2.game_score_;
    }
    if(state_1.level != state_2.level)
    {
      return state_1.level < state_2.level;
    }  
      if(state_1.damage != state_2.damage)
    {
      return state_1.damage < state_2.damage;
    }
    return state_1.live < state_2.live;
}

using State = State;

// ビーム幅と制限時間(ms)を指定してビームサーチで行動を決定する
char beamSearchActionWithTimeThreshold(
    const State &state,
    const int beam_width,
    const int64_t time_threshold)
{
    auto time_keeper = TimeKeeper(time_threshold);
    auto legal_actions = state.legalActions();
    std::priority_queue<State> now_beam;
    State best_state = state;
    State dead_state;
    dead_state.live = 0;
    ll beamH = 10;
    vector<vector<State>>beam_vv(beamH+1);
    vector<vector<ll>>score_vv(beamH+1);
    rep(i,0,beamH+1)beam_vv[i].resize(W);
    rep(i,0,beamH+1)score_vv[i].resize(W,-1);
    score_vv[0][state.self_x] = 0;
    beam_vv[0][state.self_x] = state;
  //  cerr << "test" << endl;
    for (int t = 0; t < beamH; t++)
    {
       if (time_keeper.isTimeOver())
            {
                return best_state.first_action_;
            }
      for (int x = 0; x < W; x++)
      {
        
        if (time_keeper.isTimeOver())
            {
                return best_state.first_action_;
            }
        if(score_vv[t][x] == -1)continue;
    //    cerr << t << " " << x << endl;
            State now_state = beam_vv[t][x];
            auto legal_actions = now_state.legalActions();
            for (const auto &action : legal_actions)
            {
                State next_state = now_state;
                next_state.advance(action);
                next_state.input(0);
                next_state.evaluateScore();
           //     cerr << next_state.damage << " " << next_state.self_x << " "  << t << " " << x << endl;
                if (t == 0)
                    next_state.first_action_ = action;
              
                chmax(best_state,next_state);
                best_state = next_state;
                if(score_vv[t+1][next_state.self_x] == -1){
                  score_vv[t+1][next_state.self_x] = 0;
                  beam_vv[t+1][next_state.self_x] = next_state;
                }else{
                  //re の原因
                 // if(t + 1 <= beamH && next_state.self_x >= 0 && next_state.self_x < W)chmax(beam_vv[t+1][next_state.self_x],next_state);
                 chmax(beam_vv[t+1][next_state.self_x],next_state);
                
                }
            }      
      }
    }
    
    return best_state.first_action_;
}

// ビーム幅と制限時間(ms)を指定してビームサーチで行動を決定する
char GreedySearchActionWithTimeThreshold(
    const State &state,
    const int beam_width,
    const int64_t time_threshold)
{
    auto time_keeper = TimeKeeper(time_threshold);
    auto legal_actions = state.legalActions();
    std::priority_queue<State> now_beam;
    State best_state = state;
    char action = 'S';
    char max_action = 'S';
    best_state.advance(action);
    best_state.first_action_ = action;
    best_state.input(0);
    best_state.evaluateScore();
  
    action = 'L';
    State next_state;
    next_state = state;
    while(next_state.self_x != 0){
      next_state.advance(action);
      next_state.first_action_ = action;
      next_state.input(0);
      next_state.evaluateScore();
      if(chmax(best_state,next_state))max_action = action;
    }
    action = 'R';
    next_state = state;
    while(next_state.self_x != W-1){
      next_state.advance(action);
      next_state.first_action_ = action;
      next_state.input(0);
      next_state.evaluateScore();
      if(chmax(best_state,next_state))max_action = action;
    }
  
    return max_action;

    /*
    State dead_state;
    dead_state.live = 0;
    
    ll beamH = 10;
    vector<vector<State>>beam_vv(beamH+1);
    vector<vector<ll>>score_vv(beamH+1);
    rep(i,0,beamH+1)beam_vv[i].resize(W);
    rep(i,0,beamH+1)score_vv[i].resize(W,-1);
    score_vv[0][state.self_x] = 0;
    beam_vv[0][state.self_x] = state;
  //  cerr << "test" << endl;
    for (int t = 0; t < beamH; t++)
    {
       if (time_keeper.isTimeOver())
            {
                return best_state.first_action_;
            }
      for (int x = 0; x < W; x++)
      {
        
        if (time_keeper.isTimeOver())
            {
                return best_state.first_action_;
            }
        if(score_vv[t][x] == -1)continue;
    //    cerr << t << " " << x << endl;
            State now_state = beam_vv[t][x];
            auto legal_actions = now_state.legalActions();
            for (const auto &action : legal_actions)
            {
                State next_state = now_state;
                next_state.advance(action);
                next_state.input(0);
                next_state.evaluateScore();
           //     cerr << next_state.damage << " " << next_state.self_x << " "  << t << " " << x << endl;
                if (t == 0)
                    next_state.first_action_ = action;
              
                chmax(best_state,next_state);
                best_state = next_state;
                if(score_vv[t+1][next_state.self_x] == -1){
                  score_vv[t+1][next_state.self_x] = 0;
                  beam_vv[t+1][next_state.self_x] = next_state;
                }else{
                  //re の原因
                 // if(t + 1 <= beamH && next_state.self_x >= 0 && next_state.self_x < W)chmax(beam_vv[t+1][next_state.self_x],next_state);
                 chmax(beam_vv[t+1][next_state.self_x],next_state);
                
                }
            }      
      }
    }
    
    return best_state.first_action_;
    */
}

void _main() {
  ll turn_cnt = 0;
  State state(1);
  while (!state.isDone())
  {
    state.input(1);
    turn_cnt++;
    //cerr << "input correct" << endl;
    if(state.isDone())break;
    char next_action = GreedySearchActionWithTimeThreshold(state,  3,  1);
    state.advance(next_action);
    cout << next_action << endl;
    if(turn_cnt == 1000)return;
  }
  
  /*
  rep(j,0,1000){
    ll n;
    cin >> n;
    if(n == -1)return;
    rep(i,0,n){
                ll h,p,x;
                cin >> h >> p >> x;
                board[x][H-1].sh_ = h;
                board[x][H-1].h_ = h;
                board[x][H-1].p_ = p; 
    }
    if(j % 3 == 0)cout << 'S' << endl;
    if(j % 3 == 1)cout << 'L' << endl;
    if(j % 3 == 2)cout << 'R' << endl;
    
  }
  */
}
0