結果

問題 No.5017 Tool-assisted Shooting
ユーザー Shun_PIShun_PI
提出日時 2023-07-16 18:30:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,584 ms / 2,000 ms
コード長 6,389 bytes
コンパイル時間 5,800 ms
コンパイル使用メモリ 219,168 KB
実行使用メモリ 24,492 KB
スコア 4,478,012
平均クエリ数 990.00
最終ジャッジ日時 2023-07-16 18:33:57
合計ジャッジ時間 147,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,350 ms
23,640 KB
testcase_01 AC 1,435 ms
23,856 KB
testcase_02 AC 1,198 ms
23,532 KB
testcase_03 AC 1,385 ms
24,372 KB
testcase_04 AC 1,295 ms
23,400 KB
testcase_05 AC 1,309 ms
23,400 KB
testcase_06 AC 1,326 ms
23,832 KB
testcase_07 AC 1,366 ms
23,388 KB
testcase_08 AC 1,299 ms
23,436 KB
testcase_09 AC 1,287 ms
23,856 KB
testcase_10 AC 1,418 ms
23,544 KB
testcase_11 AC 1,260 ms
23,664 KB
testcase_12 AC 1,356 ms
23,448 KB
testcase_13 AC 1,398 ms
23,388 KB
testcase_14 AC 1,414 ms
23,556 KB
testcase_15 AC 1,363 ms
23,544 KB
testcase_16 AC 1,279 ms
23,376 KB
testcase_17 AC 1,429 ms
24,324 KB
testcase_18 AC 1,417 ms
24,372 KB
testcase_19 AC 1,426 ms
24,384 KB
testcase_20 AC 1,382 ms
23,556 KB
testcase_21 AC 1,412 ms
23,460 KB
testcase_22 AC 1,221 ms
23,388 KB
testcase_23 AC 1,296 ms
23,388 KB
testcase_24 AC 1,439 ms
23,424 KB
testcase_25 AC 1,437 ms
24,000 KB
testcase_26 AC 1,318 ms
23,676 KB
testcase_27 AC 1,318 ms
24,060 KB
testcase_28 AC 1,469 ms
24,072 KB
testcase_29 AC 1,211 ms
24,084 KB
testcase_30 AC 1,222 ms
24,360 KB
testcase_31 AC 1,303 ms
24,492 KB
testcase_32 AC 1,426 ms
23,436 KB
testcase_33 AC 1,467 ms
23,844 KB
testcase_34 AC 1,311 ms
23,652 KB
testcase_35 AC 1,368 ms
24,360 KB
testcase_36 AC 1,285 ms
23,556 KB
testcase_37 AC 1,448 ms
23,988 KB
testcase_38 AC 1,394 ms
23,412 KB
testcase_39 AC 1,383 ms
23,388 KB
testcase_40 AC 1,416 ms
24,048 KB
testcase_41 AC 1,298 ms
23,988 KB
testcase_42 AC 1,449 ms
24,000 KB
testcase_43 AC 1,339 ms
24,300 KB
testcase_44 AC 1,414 ms
23,436 KB
testcase_45 AC 1,363 ms
24,060 KB
testcase_46 AC 1,375 ms
24,372 KB
testcase_47 AC 1,268 ms
23,424 KB
testcase_48 AC 1,443 ms
23,424 KB
testcase_49 AC 1,367 ms
23,544 KB
testcase_50 AC 1,353 ms
24,060 KB
testcase_51 AC 1,382 ms
23,676 KB
testcase_52 AC 1,426 ms
23,376 KB
testcase_53 AC 1,381 ms
23,376 KB
testcase_54 AC 1,428 ms
23,844 KB
testcase_55 AC 1,321 ms
24,012 KB
testcase_56 AC 1,343 ms
23,664 KB
testcase_57 AC 1,303 ms
24,060 KB
testcase_58 AC 1,349 ms
23,556 KB
testcase_59 AC 1,449 ms
23,652 KB
testcase_60 AC 1,385 ms
24,012 KB
testcase_61 AC 1,290 ms
24,060 KB
testcase_62 AC 1,309 ms
23,556 KB
testcase_63 AC 1,437 ms
23,412 KB
testcase_64 AC 1,430 ms
24,288 KB
testcase_65 AC 1,584 ms
24,048 KB
testcase_66 AC 1,435 ms
24,084 KB
testcase_67 AC 1,351 ms
24,360 KB
testcase_68 AC 1,336 ms
24,372 KB
testcase_69 AC 1,338 ms
24,360 KB
testcase_70 AC 1,406 ms
23,400 KB
testcase_71 AC 1,430 ms
23,400 KB
testcase_72 AC 1,204 ms
23,844 KB
testcase_73 AC 1,396 ms
23,652 KB
testcase_74 AC 1,280 ms
24,060 KB
testcase_75 AC 1,404 ms
23,424 KB
testcase_76 AC 1,464 ms
24,348 KB
testcase_77 AC 1,471 ms
23,544 KB
testcase_78 AC 1,401 ms
23,616 KB
testcase_79 AC 1,399 ms
24,012 KB
testcase_80 AC 1,425 ms
23,544 KB
testcase_81 AC 1,347 ms
23,676 KB
testcase_82 AC 1,328 ms
24,384 KB
testcase_83 AC 1,356 ms
23,844 KB
testcase_84 AC 1,434 ms
23,664 KB
testcase_85 AC 1,457 ms
23,664 KB
testcase_86 AC 1,405 ms
23,664 KB
testcase_87 AC 1,360 ms
23,676 KB
testcase_88 AC 1,440 ms
23,388 KB
testcase_89 AC 1,385 ms
23,388 KB
testcase_90 AC 1,429 ms
23,844 KB
testcase_91 AC 1,504 ms
23,436 KB
testcase_92 AC 1,258 ms
23,532 KB
testcase_93 AC 1,392 ms
23,652 KB
testcase_94 AC 1,264 ms
23,676 KB
testcase_95 AC 1,427 ms
23,400 KB
testcase_96 AC 1,458 ms
23,628 KB
testcase_97 AC 1,401 ms
23,988 KB
testcase_98 AC 1,365 ms
23,544 KB
testcase_99 AC 1,339 ms
24,336 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;
    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 = 4;
        int BEAM_WIDTH = 10;
        vector<vector<State>> states(BEAM_DEPTH+1);
        states[0].push_back({cur_x, 0, cur_power, {}, INF, 0});
        REP(zz, BEAM_DEPTH) {
            sort(ALL(states[zz]));
            REP(ptr, (int)min(BEAM_WIDTH, (int)states[zz].size())) {
                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) for(int d : {-1, 1, 0}) {
                    int x = (i + d + 25) % 25;
                    int y = j + 1;
                    if(is_enemy[x][y] || 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;
                    int x = enemy[i].x;
                    int y = enemy[i].y;
                    int miny = INF;
                    while(true) {
                        y--;
                        if(y == -1) break;
                        if(is_enemy[x][y]) break;
                        if(dp[x][y] != INF) miny = y;
                    }
                    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 > 800) 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;
            }
        }
    }

    cerr << score_sum << endl;
}
0