結果

問題 No.5017 Tool-assisted Shooting
ユーザー Shun_PIShun_PI
提出日時 2023-07-16 19:10:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,940 ms / 2,000 ms
コード長 6,874 bytes
コンパイル時間 4,180 ms
コンパイル使用メモリ 220,028 KB
実行使用メモリ 24,336 KB
スコア 4,289,856
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-16 19:14:16
合計ジャッジ時間 203,684 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,925 ms
23,988 KB
testcase_01 AC 1,925 ms
24,012 KB
testcase_02 AC 1,926 ms
24,324 KB
testcase_03 AC 1,926 ms
23,640 KB
testcase_04 AC 1,925 ms
23,820 KB
testcase_05 AC 1,925 ms
23,364 KB
testcase_06 AC 1,925 ms
23,652 KB
testcase_07 AC 1,925 ms
23,400 KB
testcase_08 AC 1,926 ms
24,036 KB
testcase_09 AC 1,926 ms
23,664 KB
testcase_10 AC 1,924 ms
24,000 KB
testcase_11 AC 1,925 ms
23,508 KB
testcase_12 AC 1,925 ms
23,400 KB
testcase_13 AC 1,924 ms
23,388 KB
testcase_14 AC 1,925 ms
23,544 KB
testcase_15 AC 1,925 ms
23,664 KB
testcase_16 AC 1,926 ms
23,664 KB
testcase_17 AC 1,928 ms
23,544 KB
testcase_18 AC 1,926 ms
24,012 KB
testcase_19 AC 1,926 ms
24,060 KB
testcase_20 AC 1,924 ms
24,072 KB
testcase_21 AC 1,923 ms
23,388 KB
testcase_22 AC 1,925 ms
23,364 KB
testcase_23 AC 1,926 ms
23,352 KB
testcase_24 AC 1,927 ms
23,640 KB
testcase_25 AC 1,934 ms
23,856 KB
testcase_26 AC 1,926 ms
23,400 KB
testcase_27 AC 1,925 ms
23,388 KB
testcase_28 AC 1,926 ms
23,628 KB
testcase_29 AC 1,925 ms
23,376 KB
testcase_30 AC 1,925 ms
24,036 KB
testcase_31 AC 1,927 ms
24,336 KB
testcase_32 AC 1,939 ms
24,300 KB
testcase_33 AC 1,926 ms
23,436 KB
testcase_34 AC 1,925 ms
23,508 KB
testcase_35 AC 1,927 ms
24,012 KB
testcase_36 AC 1,940 ms
23,664 KB
testcase_37 AC 1,926 ms
24,012 KB
testcase_38 AC 1,926 ms
24,024 KB
testcase_39 AC 1,926 ms
23,412 KB
testcase_40 AC 1,925 ms
24,024 KB
testcase_41 AC 1,925 ms
23,508 KB
testcase_42 AC 1,926 ms
23,412 KB
testcase_43 AC 1,926 ms
24,336 KB
testcase_44 AC 1,925 ms
23,652 KB
testcase_45 AC 1,926 ms
23,400 KB
testcase_46 AC 1,925 ms
24,036 KB
testcase_47 AC 1,923 ms
24,264 KB
testcase_48 AC 1,926 ms
23,364 KB
testcase_49 AC 1,926 ms
24,024 KB
testcase_50 AC 1,925 ms
23,640 KB
testcase_51 AC 1,925 ms
24,324 KB
testcase_52 AC 1,925 ms
24,312 KB
testcase_53 AC 1,926 ms
23,664 KB
testcase_54 AC 1,926 ms
24,024 KB
testcase_55 AC 1,926 ms
23,652 KB
testcase_56 AC 1,925 ms
23,436 KB
testcase_57 AC 1,926 ms
23,640 KB
testcase_58 AC 1,924 ms
23,364 KB
testcase_59 AC 1,926 ms
24,000 KB
testcase_60 AC 1,926 ms
23,832 KB
testcase_61 AC 1,925 ms
23,352 KB
testcase_62 AC 1,925 ms
23,640 KB
testcase_63 AC 1,925 ms
23,388 KB
testcase_64 AC 1,925 ms
23,892 KB
testcase_65 AC 1,925 ms
24,048 KB
testcase_66 AC 1,922 ms
24,012 KB
testcase_67 AC 1,926 ms
23,424 KB
testcase_68 AC 1,925 ms
24,072 KB
testcase_69 AC 1,924 ms
23,820 KB
testcase_70 AC 1,925 ms
24,024 KB
testcase_71 AC 1,926 ms
23,364 KB
testcase_72 AC 1,925 ms
23,376 KB
testcase_73 AC 1,926 ms
23,388 KB
testcase_74 AC 1,925 ms
24,024 KB
testcase_75 AC 1,926 ms
24,012 KB
testcase_76 AC 1,925 ms
23,832 KB
testcase_77 AC 1,925 ms
24,048 KB
testcase_78 AC 1,925 ms
23,652 KB
testcase_79 AC 1,115 ms
23,556 KB
testcase_80 AC 1,925 ms
23,388 KB
testcase_81 AC 1,926 ms
23,640 KB
testcase_82 AC 1,924 ms
23,616 KB
testcase_83 AC 1,926 ms
24,336 KB
testcase_84 AC 1,927 ms
23,844 KB
testcase_85 AC 1,924 ms
23,628 KB
testcase_86 AC 1,926 ms
23,376 KB
testcase_87 AC 1,926 ms
23,436 KB
testcase_88 AC 1,926 ms
23,652 KB
testcase_89 AC 1,927 ms
24,000 KB
testcase_90 AC 1,926 ms
23,652 KB
testcase_91 AC 1,925 ms
23,640 KB
testcase_92 AC 1,923 ms
23,616 KB
testcase_93 AC 1,926 ms
23,808 KB
testcase_94 AC 1,926 ms
23,964 KB
testcase_95 AC 1,924 ms
23,424 KB
testcase_96 AC 1,923 ms
24,060 KB
testcase_97 AC 1,925 ms
23,520 KB
testcase_98 AC 1,926 ms
24,024 KB
testcase_99 AC 1,924 ms
24,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 1e9;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
vector<int> dx = {-1, -1, 0, 0, 1, 1};
vector<int> dy = {-1, 0, -1, 1, 0, 1};
struct Enemy {
    int x, y = 59, h, p, init_h;
};
struct State {
    int x, y, p;
    unordered_set<int> defeated_enemy;
    int best_move = INF;
    int sumh = 0;
    double value = 0;
    bool operator < (const State &rhs) const {
        return value < rhs.value;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //vector<int> P(25);
    //REP(i, 25) cin >> P[i];
    vector<int> enemy_cnt(25);
    int enemy_s = 0;
    vector<Enemy> enemy;
    int cur_x = 12;
    int cur_power = 100;
    int score_sum = 0;
    auto start = chrono::system_clock::now();
    FOR(turn, 1, 1001) {
        cerr << turn << " " << cur_x << " " << cur_power << " " << score_sum << endl;

        FOR(i, enemy_s, enemy.size()) {
            enemy[i].y--;
            if(enemy[i].y == -1) enemy_s++;
        }

        int n;
        cin >> n;
        if(n == -1) return 0;
        REP(i, n) {
            Enemy e;
            cin >> e.h >> e.p >> e.x;
            e.init_h = e.h;
            enemy.push_back(e);
        }
        REP(i, n) enemy_cnt[enemy[i].x]++;

        //倒した敵の集合->状態 を管理してループを回す
        //k体の敵を最速で倒せる状態を求める
        double min_value = INF;
        int best_move = 0;
        int BEAM_DEPTH = 99;
        int BEAM_WIDTH = 8;
        vector<vector<State>> states(BEAM_DEPTH+1);
        states[0].push_back({cur_x, 0, cur_power, {}, INF, 0});
        bool end = false;
        REP(zz, BEAM_DEPTH) {
            if(end) break;
            sort(ALL(states[zz]));
            REP(ptr, (int)min(BEAM_WIDTH, (int)states[zz].size())) {
                double time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();
                if(time >= turn*1.9) end = true;
                if(end) break;
                State st = states[zz][ptr];

                vector<vector<bool>> is_enemy(25, vector<bool>(60));
                FOR(i, enemy_s, enemy.size()) if(enemy[i].h > 0 && !st.defeated_enemy.count(i)) is_enemy[enemy[i].x][enemy[i].y] = true;

                //ある敵のみを倒すことを考えて移動した場合を考える
                //倒した敵の集合を管理
                //その敵に相対することのできる位置までの最小距離をDPで求める
                //その敵を倒せるかどうかを判定
                vector<vector<int>> dp(25, vector<int>(60, INF));
                vector<vector<int>> dpd(25, vector<int>(60, INF));
                dp[st.x][st.y] = 0;
                dpd[st.x][st.y] = 0;
                FOR(j, st.y, 59) REP(i, 25) if(dp[i][j] != INF && !is_enemy[i][j]) for(int d : {-1, 1, 0}) {
                    int x = (i + d + 25) % 25;
                    int y = j + 1;
                    if(is_enemy[x][y-1]) continue;
                    dp[x][y] = dp[i][j] + 1;
                    if(i == cur_x && j == 0) dpd[x][y] = d;
                    else dpd[x][y] = dpd[i][j];
                }

                FOR(i, enemy_s, enemy.size()) {
                    if(enemy[i].h <= 0) continue;
                    if(st.defeated_enemy.count(i)) continue;
                    if(enemy[i].y < st.y) continue;
                    int x = enemy[i].x;
                    int y = enemy[i].y;
                    int miny = INF;
                    while(true) {
                        if(dp[x][y] != INF) miny = y;
                        y--;
                        if(y == -1) break;
                        if(is_enemy[x][y]) break;
                    }
                    if(miny == INF) continue;
                    int dist = enemy[i].y - miny;
                    int need_turn = enemy[i].h / (st.p / 100) + (enemy[i].h % (st.p/100) != 0);
                    if(need_turn > dist) continue;
                    double value = 0;
                    value = -(double)(st.p + enemy[i].p - cur_power) / (miny+need_turn+1) - st.defeated_enemy.size()*10000;
                    if(turn > 700) value = -(double)(st.sumh + enemy[i].h) / (miny+need_turn+1) - st.defeated_enemy.size()*10000;
                    if(value < min_value) {
                        min_value = value;
                        if(st.best_move == INF) best_move = dpd[x][miny];
                        else best_move = st.best_move;
                    }

                    //状態の追加
                    State nst;
                    nst.x = x;
                    nst.y = miny + need_turn;
                    nst.p = st.p + enemy[i].p;
                    for(int j : st.defeated_enemy) nst.defeated_enemy.insert(j);
                    nst.defeated_enemy.insert(i);
                    nst.best_move = st.best_move;
                    nst.sumh = st.sumh + enemy[i].init_h;
                    nst.value = value;
                    if(st.best_move == INF) nst.best_move = dpd[x][miny];
                    states[zz+1].push_back(nst);

                }
            }
        }

        if(best_move == 0) cout << "S" << endl;
        else if(best_move == -1) cout << "L" << endl;
        else cout << "R" << endl;
        cout.flush();
        cur_x = (cur_x + best_move + 25) % 25;

        //update
        int min_y = INF;
        int damage_enemy = -1;
        FOR(i, enemy_s, enemy.size()) {
            if(enemy[i].x == cur_x && enemy[i].y >= 0 && enemy[i].y < min_y && enemy[i].h > 0) {
                min_y = enemy[i].y;
                damage_enemy = i;
            }
        }
        if(damage_enemy != -1) {
            enemy[damage_enemy].h -= (cur_power/100);
            if(enemy[damage_enemy].h <= 0) {
                cur_power += enemy[damage_enemy].p;
                score_sum += enemy[damage_enemy].init_h;
            }
        }
    }

    double time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();
    cerr << time << endl;
    cerr << score_sum << endl;
}
0