結果

問題 No.5017 Tool-assisted Shooting
ユーザー Shun_PIShun_PI
提出日時 2023-07-16 18:22:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,157 ms / 2,000 ms
コード長 5,953 bytes
コンパイル時間 3,633 ms
コンパイル使用メモリ 211,420 KB
実行使用メモリ 24,396 KB
スコア 4,317,208
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-16 18:24:22
合計ジャッジ時間 93,805 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 834 ms
23,448 KB
testcase_01 AC 921 ms
23,424 KB
testcase_02 AC 662 ms
23,844 KB
testcase_03 AC 841 ms
24,360 KB
testcase_04 AC 741 ms
24,060 KB
testcase_05 AC 767 ms
23,412 KB
testcase_06 AC 830 ms
24,048 KB
testcase_07 AC 870 ms
23,424 KB
testcase_08 AC 753 ms
23,424 KB
testcase_09 AC 767 ms
23,544 KB
testcase_10 AC 884 ms
23,616 KB
testcase_11 AC 712 ms
23,640 KB
testcase_12 AC 808 ms
23,868 KB
testcase_13 AC 852 ms
23,676 KB
testcase_14 AC 897 ms
23,556 KB
testcase_15 AC 807 ms
24,060 KB
testcase_16 AC 761 ms
24,024 KB
testcase_17 AC 885 ms
23,652 KB
testcase_18 AC 860 ms
23,916 KB
testcase_19 AC 891 ms
24,048 KB
testcase_20 AC 837 ms
24,336 KB
testcase_21 AC 908 ms
23,664 KB
testcase_22 AC 697 ms
24,360 KB
testcase_23 AC 761 ms
23,640 KB
testcase_24 AC 906 ms
23,424 KB
testcase_25 AC 950 ms
23,388 KB
testcase_26 AC 798 ms
23,376 KB
testcase_27 AC 820 ms
24,384 KB
testcase_28 AC 956 ms
23,400 KB
testcase_29 AC 684 ms
24,048 KB
testcase_30 AC 691 ms
24,288 KB
testcase_31 AC 772 ms
23,532 KB
testcase_32 AC 902 ms
24,216 KB
testcase_33 AC 990 ms
23,424 KB
testcase_34 AC 816 ms
23,664 KB
testcase_35 AC 851 ms
23,664 KB
testcase_36 AC 735 ms
23,388 KB
testcase_37 AC 865 ms
23,556 KB
testcase_38 AC 883 ms
23,424 KB
testcase_39 AC 854 ms
23,652 KB
testcase_40 AC 905 ms
23,436 KB
testcase_41 AC 799 ms
23,616 KB
testcase_42 AC 914 ms
23,568 KB
testcase_43 AC 830 ms
23,628 KB
testcase_44 AC 872 ms
24,396 KB
testcase_45 AC 868 ms
23,556 KB
testcase_46 AC 906 ms
23,676 KB
testcase_47 AC 726 ms
24,300 KB
testcase_48 AC 936 ms
23,436 KB
testcase_49 AC 846 ms
23,664 KB
testcase_50 AC 815 ms
23,544 KB
testcase_51 AC 879 ms
24,336 KB
testcase_52 AC 899 ms
24,012 KB
testcase_53 AC 867 ms
24,360 KB
testcase_54 AC 917 ms
23,424 KB
testcase_55 AC 832 ms
24,060 KB
testcase_56 AC 804 ms
23,424 KB
testcase_57 AC 748 ms
23,436 KB
testcase_58 AC 837 ms
23,388 KB
testcase_59 AC 920 ms
23,640 KB
testcase_60 AC 822 ms
23,652 KB
testcase_61 AC 779 ms
23,544 KB
testcase_62 AC 782 ms
23,640 KB
testcase_63 AC 858 ms
23,532 KB
testcase_64 AC 905 ms
23,856 KB
testcase_65 AC 1,157 ms
24,000 KB
testcase_66 AC 957 ms
23,376 KB
testcase_67 AC 834 ms
24,072 KB
testcase_68 AC 857 ms
23,556 KB
testcase_69 AC 837 ms
23,664 KB
testcase_70 AC 859 ms
24,372 KB
testcase_71 AC 865 ms
23,628 KB
testcase_72 AC 677 ms
24,000 KB
testcase_73 AC 874 ms
23,412 KB
testcase_74 AC 690 ms
23,388 KB
testcase_75 AC 909 ms
23,256 KB
testcase_76 AC 910 ms
24,360 KB
testcase_77 AC 972 ms
23,988 KB
testcase_78 AC 831 ms
23,664 KB
testcase_79 AC 849 ms
23,628 KB
testcase_80 AC 894 ms
23,664 KB
testcase_81 AC 810 ms
24,312 KB
testcase_82 AC 843 ms
23,520 KB
testcase_83 AC 803 ms
23,388 KB
testcase_84 AC 890 ms
23,664 KB
testcase_85 AC 919 ms
24,072 KB
testcase_86 AC 906 ms
23,424 KB
testcase_87 AC 794 ms
23,628 KB
testcase_88 AC 951 ms
23,988 KB
testcase_89 AC 858 ms
24,060 KB
testcase_90 AC 952 ms
23,388 KB
testcase_91 AC 974 ms
23,556 KB
testcase_92 AC 714 ms
23,544 KB
testcase_93 AC 890 ms
24,012 KB
testcase_94 AC 706 ms
23,628 KB
testcase_95 AC 914 ms
23,532 KB
testcase_96 AC 917 ms
23,556 KB
testcase_97 AC 883 ms
24,288 KB
testcase_98 AC 849 ms
23,676 KB
testcase_99 AC 876 ms
24,036 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;
};

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;
        vector<State> states;
        states.push_back({cur_x, 0, cur_power, {}, INF, 0});
        int ptr = 0;
        while(ptr < states.size()) {
            State st = states[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 > 900) 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;
                }

                if(st.defeated_enemy.size() == 0) {
                    //状態の追加
                    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;
                    if(st.best_move == INF) nst.best_move = dpd[x][miny];
                    states.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