結果

問題 No.5017 Tool-assisted Shooting
ユーザー shibh308shibh308
提出日時 2023-07-16 18:12:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 11,718 bytes
コンパイル時間 3,670 ms
コンパイル使用メモリ 241,252 KB
実行使用メモリ 35,828 KB
スコア 26,753
最終ジャッジ日時 2023-07-16 18:16:46
合計ジャッジ時間 240,648 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
testcase_45 TLE -
testcase_46 TLE -
testcase_47 TLE -
testcase_48 TLE -
testcase_49 TLE -
testcase_50 TLE -
testcase_51 TLE -
testcase_52 TLE -
testcase_53 TLE -
testcase_54 TLE -
testcase_55 TLE -
testcase_56 TLE -
testcase_57 TLE -
testcase_58 TLE -
testcase_59 TLE -
testcase_60 TLE -
testcase_61 TLE -
testcase_62 TLE -
testcase_63 TLE -
testcase_64 TLE -
testcase_65 TLE -
testcase_66 TLE -
testcase_67 TLE -
testcase_68 TLE -
testcase_69 TLE -
testcase_70 TLE -
testcase_71 TLE -
testcase_72 TLE -
testcase_73 TLE -
testcase_74 TLE -
testcase_75 TLE -
testcase_76 TLE -
testcase_77 TLE -
testcase_78 TLE -
testcase_79 TLE -
testcase_80 TLE -
testcase_81 TLE -
testcase_82 TLE -
testcase_83 TLE -
testcase_84 TLE -
testcase_85 TLE -
testcase_86 TLE -
testcase_87 TLE -
testcase_88 TLE -
testcase_89 TLE -
testcase_90 AC 1,910 ms
24,252 KB
testcase_91 TLE -
testcase_92 TLE -
testcase_93 TLE -
testcase_94 AC 1,953 ms
23,304 KB
testcase_95 TLE -
testcase_96 TLE -
testcase_97 TLE -
testcase_98 TLE -
testcase_99 TLE -
権限があれば一括ダウンロードができます

ソースコード

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 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;
        }
    };

    auto target = [&](BeamState& bs, int depth){
        // O(n^2) but fast
        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 = 40;
    constexpr int DEPTH = 45;

    auto cmp_fn = [](auto x, auto y){ return x.score() > y.score(); };

    constexpr bool tayousei = false;

    if(!tayousei){
        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 < DEPTH && 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(), cmp_fn);
            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);
        }
        return b_states.front().mov;
    }
    else{
        vector<vector<BeamState>> b_states(3);
        b_states[0].emplace_back();
        b_states[0].back().x = now_x;
        b_states[0].back().got_score = score;
        b_states[0].back().got_power = power;
        int first_tar = target(b_states[0].back(), 0);
        assert(first_tar != 0);
        b_states[0].back().target_y = first_tar;
        b_states[0].back().target_enemy_hp = get_state(now_x, first_tar).now_hp;
        b_states[1].emplace_back(b_states[0].back());
        b_states[1].back().mov = 1;
        b_states[2].emplace_back(b_states[0].back());
        b_states[2].back().mov = -1;
        for(int dep = 0; dep < height && dep + turn <= turn_max; ++dep){
            for(int st = 0; st < 3; ++st){
                vector<BeamState> b_nex;
                for(auto &b_state: b_states[st]){
                    for(auto d: {0, 1, 24}){
                        if(dep == 0){
                            if(!((st == 0 && d == 0) || (st == 1 && d == 1) || (st == 2 && d == 24))){
                                continue;
                            }
                        }
                        auto nex = b_state;
                        nex.x = (nex.x + d) % n_col;
                        int tar = target(nex, dep);
                        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(), cmp_fn);
                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[st]);
            }
        }
        vector<BeamState> bst;
        for(int i = 0; i < 3; ++i){
            if(!b_states[i].empty()){
                bst.emplace_back(b_states[i].front());
            }
        }
        sort(bst.begin(), bst.end(), cmp_fn);
        return bst.front().mov;
    }
}

int distLeft(int a, int b) {
    return a < b ? 25 + a - b : a - b;
}

int distRight(int a, int b) {
    return a < b ? b - a : 25 + b - a;
}

bool sw = false;
int solve2(int t) {
    int lv = 1 + power / 100;
    double str = ((7.5+0.15*t)+(1.5+0.03*t)) / lv;
    if (str < 2) {
        sw = true;
    }
    vector<int> miny(25, 60);
    vector<pair<int, int>> rem;
    for (int x = 0; x < 25; x++) {
        for (int y = 0; y < 60; y++) {
            auto& st = get_state(x, y);
            if (st.exists) {
                rem.emplace_back(x, y);
                miny[x] = y;
                break;
            }
        }
    }
    pair<int, int> tai = make_pair(-1, -1);
    double md = 0x1000000;
    bool canMoveLeft = miny[(now_x+24)%25]>=2;
    bool canMoveRight = miny[(now_x+1)%25]>=2;
    for (auto [mx, my] : rem) {
        auto& st = get_state(mx, my);
        int dist = now_x == mx ? 0 : 0x1000000;
        if (canMoveLeft) {
            dist = min(dist, distLeft(now_x, mx));
        }
        if (canMoveRight) {
            dist = min(dist, distRight(now_x, mx));
        }
        int turn = dist + (st.now_hp + lv - 1) / lv;
        if (my - turn <= 0) {
            continue;
        }
        double val;
        if (sw) {
            val = turn;
        } else {
            val = -((double)st.power / turn);
        }
        if (tai.first == -1 || md > val) {
            tai = make_pair(mx, my);
            md = val;
        }
    }
    cout << turn << " " << now_x << " " << tai.first << " " << distLeft(now_x, tai.first) << " " << distRight(now_x, tai.first) << " " << get_state(tai.first, tai.second).now_hp << endl;
    cout << "canmove: " << canMoveLeft << " " << canMoveRight << endl;
    if (tai.first != -1) {
        if (miny[now_x] >= 2 && tai.first == now_x) {
            return 0;
        } else if (canMoveLeft && (!canMoveRight || distLeft(tai.first, now_x) < distRight(tai.first, now_x))) {
            return -1;
        } else {
            return 1;
        }
    } else {
        if (miny[now_x] >= 2) {
            return 0;
        } else if (canMoveLeft && !canMoveRight) {
            return -1;
        } else {
            return 1;
        }
    }
}

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());
        // act(solve2(turn));
        /*
        if(turn < 1000){
            act(solve2(turn));
        }
        else{
            act(solve());
        }
         */
    }
    cerr << score << endl;

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

}
0