結果

問題 No.5017 Tool-assisted Shooting
ユーザー Yu_212Yu_212
提出日時 2023-07-16 19:06:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 836 ms / 2,000 ms
コード長 8,795 bytes
コンパイル時間 3,383 ms
コンパイル使用メモリ 240,300 KB
実行使用メモリ 24,396 KB
スコア 4,337,229
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-16 19:07:43
合計ジャッジ時間 80,984 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 733 ms
23,364 KB
testcase_01 AC 762 ms
24,324 KB
testcase_02 AC 588 ms
23,436 KB
testcase_03 AC 715 ms
23,664 KB
testcase_04 AC 624 ms
23,832 KB
testcase_05 AC 669 ms
24,072 KB
testcase_06 AC 698 ms
24,048 KB
testcase_07 AC 721 ms
23,640 KB
testcase_08 AC 657 ms
24,024 KB
testcase_09 AC 669 ms
24,036 KB
testcase_10 AC 690 ms
23,388 KB
testcase_11 AC 648 ms
23,628 KB
testcase_12 AC 755 ms
23,436 KB
testcase_13 AC 683 ms
24,360 KB
testcase_14 AC 735 ms
23,832 KB
testcase_15 AC 765 ms
23,436 KB
testcase_16 AC 600 ms
23,628 KB
testcase_17 AC 707 ms
23,628 KB
testcase_18 AC 724 ms
24,060 KB
testcase_19 AC 722 ms
23,556 KB
testcase_20 AC 723 ms
24,024 KB
testcase_21 AC 690 ms
24,072 KB
testcase_22 AC 638 ms
24,036 KB
testcase_23 AC 604 ms
23,412 KB
testcase_24 AC 735 ms
24,372 KB
testcase_25 AC 772 ms
23,652 KB
testcase_26 AC 684 ms
23,400 KB
testcase_27 AC 679 ms
24,372 KB
testcase_28 AC 737 ms
23,676 KB
testcase_29 AC 669 ms
23,532 KB
testcase_30 AC 596 ms
24,048 KB
testcase_31 AC 625 ms
23,532 KB
testcase_32 AC 732 ms
23,376 KB
testcase_33 AC 787 ms
24,072 KB
testcase_34 AC 708 ms
23,832 KB
testcase_35 AC 703 ms
24,360 KB
testcase_36 AC 659 ms
23,388 KB
testcase_37 AC 765 ms
24,252 KB
testcase_38 AC 690 ms
23,448 KB
testcase_39 AC 700 ms
23,448 KB
testcase_40 AC 741 ms
23,544 KB
testcase_41 AC 734 ms
23,544 KB
testcase_42 AC 760 ms
23,376 KB
testcase_43 AC 689 ms
23,412 KB
testcase_44 AC 702 ms
23,376 KB
testcase_45 AC 720 ms
24,060 KB
testcase_46 AC 770 ms
23,640 KB
testcase_47 AC 582 ms
23,412 KB
testcase_48 AC 786 ms
23,412 KB
testcase_49 AC 721 ms
23,664 KB
testcase_50 AC 701 ms
23,640 KB
testcase_51 AC 784 ms
24,348 KB
testcase_52 AC 719 ms
23,400 KB
testcase_53 AC 737 ms
23,844 KB
testcase_54 AC 719 ms
24,396 KB
testcase_55 AC 711 ms
23,844 KB
testcase_56 AC 642 ms
24,048 KB
testcase_57 AC 659 ms
23,556 KB
testcase_58 AC 656 ms
23,400 KB
testcase_59 AC 764 ms
23,652 KB
testcase_60 AC 668 ms
23,640 KB
testcase_61 AC 673 ms
23,544 KB
testcase_62 AC 664 ms
23,556 KB
testcase_63 AC 736 ms
23,388 KB
testcase_64 AC 743 ms
24,348 KB
testcase_65 AC 825 ms
23,424 KB
testcase_66 AC 696 ms
23,436 KB
testcase_67 AC 716 ms
23,736 KB
testcase_68 AC 671 ms
24,048 KB
testcase_69 AC 709 ms
24,384 KB
testcase_70 AC 738 ms
23,532 KB
testcase_71 AC 764 ms
23,676 KB
testcase_72 AC 617 ms
23,628 KB
testcase_73 AC 737 ms
23,628 KB
testcase_74 AC 623 ms
23,532 KB
testcase_75 AC 734 ms
23,448 KB
testcase_76 AC 836 ms
23,616 KB
testcase_77 AC 753 ms
23,424 KB
testcase_78 AC 741 ms
24,300 KB
testcase_79 AC 776 ms
23,544 KB
testcase_80 AC 758 ms
24,048 KB
testcase_81 AC 715 ms
23,388 KB
testcase_82 AC 699 ms
24,024 KB
testcase_83 AC 666 ms
24,384 KB
testcase_84 AC 660 ms
24,024 KB
testcase_85 AC 759 ms
23,568 KB
testcase_86 AC 723 ms
23,844 KB
testcase_87 AC 634 ms
24,360 KB
testcase_88 AC 754 ms
23,436 KB
testcase_89 AC 670 ms
23,664 KB
testcase_90 AC 799 ms
23,676 KB
testcase_91 AC 804 ms
23,640 KB
testcase_92 AC 640 ms
23,388 KB
testcase_93 AC 717 ms
23,844 KB
testcase_94 AC 654 ms
23,364 KB
testcase_95 AC 799 ms
24,024 KB
testcase_96 AC 766 ms
23,376 KB
testcase_97 AC 717 ms
23,532 KB
testcase_98 AC 796 ms
24,048 KB
testcase_99 AC 731 ms
24,264 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 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 WIDTH = 25;
constexpr int DEPTH = 45;
constexpr int SWITCH = 762;
double power_weight = 4.289958881617464e-06;
double hp_weight = 4.289958881617464e-06;
double score_weight = 2.3081801550296716e-08;


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;
        int dep = 0;
        double score() const{
            double w = pow(double(turn + dep) / turn_max, 2.0) + 1e-6;
            return (1 - w) * (power_weight * got_power - hp_weight * target_enemy_hp) + w * score_weight * 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;
    };

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

    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.dep = dep;
                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;
}

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;
        cout << "turn: " << t << endl;
    }
     */
    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;
        }
    }
    if (tai.first != -1) {
        if (miny[now_x] >= 2 && tai.first == now_x) {
            return 0;
        } else if (canMoveLeft && (!canMoveRight || distLeft(now_x, tai.first) < distRight(now_x, tai.first))) {
            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));
    bool sw = false;
    for(turn = 0; turn < turn_max; ++turn){
        bool res = input();
        assert(res);
        int lv = 1 + power / 100;
        double str = ((7.5+0.15*turn)+(1.5+0.03*turn)) / lv;
        sw |= str < 2;
        if(!sw){
            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