結果

問題 No.5017 Tool-assisted Shooting
ユーザー shibh308shibh308
提出日時 2023-07-16 17:17:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,384 ms / 2,000 ms
コード長 7,741 bytes
コンパイル時間 3,575 ms
コンパイル使用メモリ 236,988 KB
実行使用メモリ 24,360 KB
スコア 3,869,583
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-16 17:19:55
合計ジャッジ時間 134,308 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,234 ms
23,988 KB
testcase_01 AC 1,268 ms
23,592 KB
testcase_02 AC 1,074 ms
24,312 KB
testcase_03 AC 1,284 ms
23,964 KB
testcase_04 AC 1,084 ms
23,772 KB
testcase_05 AC 1,171 ms
24,228 KB
testcase_06 AC 1,269 ms
24,240 KB
testcase_07 AC 1,275 ms
24,300 KB
testcase_08 AC 1,179 ms
23,568 KB
testcase_09 AC 1,198 ms
23,304 KB
testcase_10 AC 1,210 ms
23,988 KB
testcase_11 AC 1,149 ms
23,304 KB
testcase_12 AC 1,218 ms
23,328 KB
testcase_13 AC 1,284 ms
24,192 KB
testcase_14 AC 1,320 ms
23,328 KB
testcase_15 AC 1,345 ms
23,472 KB
testcase_16 AC 1,190 ms
23,784 KB
testcase_17 AC 1,295 ms
23,976 KB
testcase_18 AC 1,245 ms
24,216 KB
testcase_19 AC 1,206 ms
23,496 KB
testcase_20 AC 1,283 ms
23,568 KB
testcase_21 AC 1,280 ms
23,352 KB
testcase_22 AC 1,154 ms
23,316 KB
testcase_23 AC 1,199 ms
23,484 KB
testcase_24 AC 1,278 ms
23,484 KB
testcase_25 AC 1,296 ms
23,784 KB
testcase_26 AC 1,203 ms
23,796 KB
testcase_27 AC 1,152 ms
23,184 KB
testcase_28 AC 1,368 ms
23,784 KB
testcase_29 AC 1,143 ms
23,568 KB
testcase_30 AC 1,182 ms
23,784 KB
testcase_31 AC 1,210 ms
23,352 KB
testcase_32 AC 1,324 ms
23,352 KB
testcase_33 AC 1,329 ms
23,340 KB
testcase_34 AC 1,253 ms
23,328 KB
testcase_35 AC 1,275 ms
24,000 KB
testcase_36 AC 1,115 ms
24,360 KB
testcase_37 AC 1,236 ms
23,340 KB
testcase_38 AC 1,261 ms
23,976 KB
testcase_39 AC 1,230 ms
23,352 KB
testcase_40 AC 1,237 ms
23,376 KB
testcase_41 AC 1,281 ms
23,976 KB
testcase_42 AC 1,286 ms
23,772 KB
testcase_43 AC 1,192 ms
23,328 KB
testcase_44 AC 1,289 ms
23,976 KB
testcase_45 AC 1,245 ms
23,376 KB
testcase_46 AC 1,320 ms
23,580 KB
testcase_47 AC 1,153 ms
23,376 KB
testcase_48 AC 1,281 ms
23,364 KB
testcase_49 AC 1,086 ms
23,304 KB
testcase_50 AC 1,286 ms
23,340 KB
testcase_51 AC 1,082 ms
23,988 KB
testcase_52 AC 1,268 ms
23,496 KB
testcase_53 AC 1,193 ms
23,976 KB
testcase_54 AC 1,257 ms
23,760 KB
testcase_55 AC 1,205 ms
23,604 KB
testcase_56 AC 1,219 ms
23,568 KB
testcase_57 AC 1,169 ms
23,376 KB
testcase_58 AC 1,232 ms
23,328 KB
testcase_59 AC 1,319 ms
23,592 KB
testcase_60 AC 1,235 ms
24,276 KB
testcase_61 AC 1,170 ms
24,204 KB
testcase_62 AC 1,208 ms
23,328 KB
testcase_63 AC 1,219 ms
23,352 KB
testcase_64 AC 1,208 ms
23,352 KB
testcase_65 AC 1,384 ms
23,304 KB
testcase_66 AC 1,276 ms
23,988 KB
testcase_67 AC 1,229 ms
23,952 KB
testcase_68 AC 1,266 ms
24,204 KB
testcase_69 AC 1,173 ms
23,604 KB
testcase_70 AC 1,199 ms
24,216 KB
testcase_71 AC 1,165 ms
23,376 KB
testcase_72 AC 1,176 ms
24,324 KB
testcase_73 AC 1,271 ms
23,352 KB
testcase_74 AC 1,091 ms
24,216 KB
testcase_75 AC 1,264 ms
24,300 KB
testcase_76 AC 1,289 ms
23,472 KB
testcase_77 AC 1,354 ms
23,604 KB
testcase_78 AC 1,270 ms
23,376 KB
testcase_79 AC 1,148 ms
23,952 KB
testcase_80 AC 1,248 ms
23,352 KB
testcase_81 AC 1,209 ms
23,352 KB
testcase_82 AC 1,253 ms
23,976 KB
testcase_83 AC 1,272 ms
24,000 KB
testcase_84 AC 1,242 ms
23,940 KB
testcase_85 AC 1,290 ms
23,484 KB
testcase_86 AC 1,185 ms
23,580 KB
testcase_87 AC 1,246 ms
23,364 KB
testcase_88 AC 1,305 ms
23,472 KB
testcase_89 AC 1,234 ms
23,976 KB
testcase_90 AC 1,228 ms
23,976 KB
testcase_91 AC 1,281 ms
23,316 KB
testcase_92 AC 1,131 ms
23,604 KB
testcase_93 AC 1,299 ms
23,568 KB
testcase_94 AC 1,155 ms
23,988 KB
testcase_95 AC 1,270 ms
23,592 KB
testcase_96 AC 1,258 ms
23,568 KB
testcase_97 AC 1,279 ms
23,964 KB
testcase_98 AC 1,273 ms
23,328 KB
testcase_99 AC 1,222 ms
23,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include "atcoder/all"

// #define FROMFILE

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18);

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}


template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


namespace Rnd{
// doc: https://shibh308.github.io/library/library/lib/functions/xorshift.cpp.html
uint64_t x = 0xdeadbeef0110dead;
uint64_t rnd(){
    x ^= x << 7;
    x ^= x >> 9;
    return x;
}
uint64_t rnd(int n){
    return rnd() % n;
}
double rnd_double(){
    return 1.0 * rnd() / numeric_limits<uint64_t>::max();
}
vector<int> rnd_perm(int n){
    vector<int> v(n);
    iota(v.begin(), v.end(), 0);
    for(int i = n - 1; i >= 1; --i){
        int j = rnd(i + 1);
        swap(v[i], v[j]);
    }
    return v;
}
template<typename T>
void shuffle(vector<T>& v){
    int n = v.size();
    for(int i = n - 1; i >= 1; --i){
        int j = rnd(i + 1);
        swap(v[i], v[j]);
    }
}
}


namespace params{
void load_params(){
    ifstream ifs("../params.txt");
    assert(ifs.is_open());

    // TODO: load params
}
}

void read_file(istream& ifs){
    // TODO: read from file
}


constexpr int turn_max = 1000;
constexpr int n_col = 25;
constexpr int height = 60;
int turn = 0;
int now_x = 12;
struct State{
    bool exists = false;
    int max_hp = -1;
    int now_hp = -1;
    int power = -1;
};
vector<vector<State>> state;
vector<vector<int>> hp_inp, power_inp, col_inp;
vector<int> col_cnt;
int power = 0;
int score = 0;

bool input(){
    int n;
    cin >> n;
    if(n == -1){
        return false;
    }
    hp_inp.emplace_back(n);
    power_inp.emplace_back(n);
    col_inp.emplace_back(n);
    for(int i = 0; i < n; ++i){
        cin >> hp_inp.back()[i] >> power_inp.back()[i] >> col_inp.back()[i];
        // spawn at (*, 59)
        state[turn + height][col_inp.back()[i]] = { true, hp_inp.back()[i], hp_inp.back()[i], power_inp.back()[i] };
        ++col_cnt[col_inp.back()[i]];
    }
    return true;
}

State& get_state(int col_, int height_){
    return state[turn + height_ + 1][col_];
};

int solve(){
    // col: [0, 25)
    // height: [0, 60)
    vector<vector<int>> target_idxes(n_col);
    for(int i = 0; i < height; ++i){
        for(int j = 0; j < n_col; ++j){
            auto& st = get_state(j, i);
            if(st.exists){
                target_idxes[j].emplace_back(i);
            }
        }
    }

    struct BeamState{
        vector<pair<int,int>> killed;
        int x;
        int target_y = 0;
        int target_enemy_hp = 0;
        int got_score = 0, got_power = 0;
        int mov = 0;
        double score() const{
            return got_power - 0.00001 * target_enemy_hp + 1.5 * got_score;
        }
        int level() const{
            return 1 + got_power / 100;
        }
        bool operator==(const BeamState& a) const{
            return killed == a.killed && target_enemy_hp == a.target_enemy_hp && x == a.x && got_power == a.got_power && got_score == a.got_score;
        }
        bool operator<(const BeamState& a) const{
            return score() < a.score();
        }
        bool operator<=(const BeamState& a) const{
            return score() <= a.score();
        }
        bool operator>(const BeamState& a) const{
            return score() > a.score();
        }
        bool operator>=(const BeamState& a) const{
            return score() >= a.score();
        }
    };

    auto target = [&](BeamState& bs, int depth){
        // TODO: speed up from O(n^2)
        for(auto y : target_idxes[bs.x]){
            if(depth <= y && find(bs.killed.begin(), bs.killed.end(), make_pair(bs.x, y)) == bs.killed.end()){
                return y;
            }
        }
        return -1;
    };

    constexpr int WIDTH = 30;


    /*
    {
        cout << "Now x: " << now_x << endl;
        for(int i = 0; i < 10; ++i){
            for(int j = 0; j < n_col; ++j){
                if(get_state(j, i).exists){
                    cout << "exist: " << j << " " << i << endl;
                }
            }
        }
        cout << endl;
    }
     */

    vector<BeamState> b_states;
    b_states.emplace_back();
    b_states.back().x = now_x;
    b_states.back().got_score = score;
    b_states.back().got_power = power;
    int first_tar = target(b_states.back(), 0);
    assert(first_tar != 0);
    b_states.back().target_y = first_tar;
    b_states.back().target_enemy_hp = get_state(now_x, first_tar).now_hp;
    for(int dep = 0; dep < height && dep + turn <= turn_max; ++dep){
        vector<BeamState> b_nex;
        for(auto& b_state : b_states){
            for(auto d : {0, 1, 24}){
                auto nex = b_state;
                nex.x = (nex.x + d) % n_col;
                int tar = target(nex, dep);
                if(dep == 0){
                    nex.mov = d == 24 ? -1 : d;
                }
                if(dep == tar){
                    continue;
                }
                if(tar != -1){
                    if(d == 0 && nex.target_y == tar){
                        nex.target_enemy_hp -= nex.level();
                    }
                    else{
                        nex.target_enemy_hp = get_state(nex.x, tar).now_hp - nex.level();
                    }
                    if(nex.target_enemy_hp <= 0){
                        nex.got_power += get_state(nex.x, tar).power;
                        nex.got_score += get_state(nex.x, tar).max_hp;
                        nex.killed.emplace_back(nex.x, tar);
                    }
                    else if(dep + 1 == tar){
                        continue;
                    }
                }
                nex.target_y = tar;
                b_nex.emplace_back(nex);
            }
        }
        sort(b_nex.begin(), b_nex.end(), greater<BeamState>());
        b_nex.erase(unique(b_nex.begin(), b_nex.end()), b_nex.end());
        if(WIDTH < b_nex.size()){
            b_nex.resize(WIDTH);
        }
        swap(b_nex, b_states);
    }
    // cerr << "score / power : " << b_states.front().got_score << " " << b_states.front().got_power << endl;
    // return 0;
    return b_states.front().mov;
}

void act(int x_diff){
    assert(!get_state(now_x, 0).exists);
    if(x_diff == -1){
        cout << 'L' << endl;
        now_x = (now_x + 24) % n_col;
    }
    if(x_diff == 0){
        cout << 'S' << endl;
    }
    if(x_diff == 1){
        cout << 'R' << endl;
        now_x = (now_x + 1) % n_col;
    }
    assert(!get_state(now_x, 0).exists);
    for(int i = 0; i < height; ++i){
        auto& st = get_state(now_x, i);
        if(st.exists){
            assert(i != 0);
            int level = 1 + power / 100;
            st.now_hp -= level;
            if(st.now_hp <= 0){
                st.exists = false;
                power += st.power;
                score += st.max_hp;
            }
            assert(!(st.now_hp > 0 && i == 1));
            break;
        }
    }
}

signed main(){
    clock_t st = clock();

#ifdef OPTIMIZE
    params::load_params();
#endif

#ifdef NOSUBMIT
    vector<int> p(25);
    for(auto& x : p){
        cin >> x;
    }
#endif
    col_cnt.resize(n_col, 0);
    state.resize(turn_max + 100, vector<State>(n_col));
    for(turn = 0; turn < turn_max; ++turn){
        bool res = input();
        assert(res);
        act(solve());
    }

/*
#ifndef FROMFILE
    // TODO: input
    read_file(cin);
#else
    ifstream ifs("../tools/in/0003.txt");
    assert(ifs.is_open());
    read_file(ifs);
#endif
 */

}
0