結果

問題 No.5017 Tool-assisted Shooting
ユーザー hari64hari64
提出日時 2023-07-16 17:44:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 6,066 bytes
コンパイル時間 2,560 ms
コンパイル使用メモリ 218,576 KB
実行使用メモリ 24,336 KB
スコア 3,553,266
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-16 17:44:51
合計ジャッジ時間 27,477 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
23,400 KB
testcase_01 AC 251 ms
23,388 KB
testcase_02 AC 180 ms
23,532 KB
testcase_03 AC 188 ms
23,448 KB
testcase_04 AC 175 ms
23,652 KB
testcase_05 AC 181 ms
24,156 KB
testcase_06 AC 164 ms
23,388 KB
testcase_07 AC 185 ms
23,328 KB
testcase_08 AC 161 ms
23,568 KB
testcase_09 AC 214 ms
23,580 KB
testcase_10 AC 196 ms
23,400 KB
testcase_11 AC 165 ms
23,364 KB
testcase_12 AC 174 ms
24,000 KB
testcase_13 AC 229 ms
23,640 KB
testcase_14 AC 234 ms
23,436 KB
testcase_15 AC 176 ms
23,688 KB
testcase_16 AC 179 ms
23,424 KB
testcase_17 AC 199 ms
24,084 KB
testcase_18 AC 183 ms
23,592 KB
testcase_19 AC 224 ms
24,192 KB
testcase_20 AC 208 ms
23,544 KB
testcase_21 AC 203 ms
23,868 KB
testcase_22 AC 146 ms
23,580 KB
testcase_23 AC 193 ms
23,376 KB
testcase_24 AC 234 ms
24,036 KB
testcase_25 AC 223 ms
23,472 KB
testcase_26 AC 191 ms
24,240 KB
testcase_27 AC 181 ms
23,364 KB
testcase_28 AC 234 ms
23,796 KB
testcase_29 AC 148 ms
23,436 KB
testcase_30 AC 152 ms
23,544 KB
testcase_31 AC 196 ms
24,096 KB
testcase_32 AC 209 ms
23,580 KB
testcase_33 AC 211 ms
23,664 KB
testcase_34 AC 203 ms
23,400 KB
testcase_35 AC 183 ms
23,388 KB
testcase_36 AC 184 ms
24,012 KB
testcase_37 AC 201 ms
24,036 KB
testcase_38 AC 209 ms
23,868 KB
testcase_39 AC 216 ms
23,472 KB
testcase_40 AC 233 ms
24,048 KB
testcase_41 AC 200 ms
23,676 KB
testcase_42 AC 198 ms
23,856 KB
testcase_43 AC 183 ms
24,240 KB
testcase_44 AC 209 ms
23,388 KB
testcase_45 AC 218 ms
23,400 KB
testcase_46 AC 208 ms
23,688 KB
testcase_47 AC 167 ms
23,784 KB
testcase_48 AC 205 ms
23,664 KB
testcase_49 AC 198 ms
23,472 KB
testcase_50 AC 215 ms
23,988 KB
testcase_51 AC 228 ms
23,400 KB
testcase_52 AC 208 ms
24,000 KB
testcase_53 AC 183 ms
24,000 KB
testcase_54 AC 199 ms
23,400 KB
testcase_55 AC 180 ms
24,336 KB
testcase_56 AC 178 ms
23,340 KB
testcase_57 AC 189 ms
23,376 KB
testcase_58 AC 221 ms
23,844 KB
testcase_59 AC 277 ms
23,808 KB
testcase_60 AC 178 ms
24,336 KB
testcase_61 AC 178 ms
23,592 KB
testcase_62 AC 188 ms
23,400 KB
testcase_63 AC 183 ms
23,544 KB
testcase_64 AC 200 ms
24,036 KB
testcase_65 AC 248 ms
23,784 KB
testcase_66 AC 181 ms
23,664 KB
testcase_67 AC 190 ms
23,856 KB
testcase_68 AC 195 ms
23,664 KB
testcase_69 AC 171 ms
23,472 KB
testcase_70 AC 193 ms
23,676 KB
testcase_71 AC 204 ms
24,048 KB
testcase_72 AC 176 ms
24,036 KB
testcase_73 AC 217 ms
23,784 KB
testcase_74 AC 159 ms
23,592 KB
testcase_75 AC 198 ms
23,376 KB
testcase_76 AC 190 ms
23,796 KB
testcase_77 AC 210 ms
23,532 KB
testcase_78 AC 237 ms
23,844 KB
testcase_79 AC 178 ms
23,508 KB
testcase_80 AC 234 ms
23,580 KB
testcase_81 AC 209 ms
23,868 KB
testcase_82 AC 188 ms
23,856 KB
testcase_83 AC 208 ms
24,048 KB
testcase_84 AC 126 ms
23,328 KB
testcase_85 AC 214 ms
23,568 KB
testcase_86 AC 205 ms
23,316 KB
testcase_87 AC 179 ms
23,556 KB
testcase_88 AC 211 ms
23,208 KB
testcase_89 AC 189 ms
23,796 KB
testcase_90 AC 250 ms
23,556 KB
testcase_91 AC 170 ms
24,252 KB
testcase_92 AC 167 ms
24,168 KB
testcase_93 AC 233 ms
24,000 KB
testcase_94 AC 168 ms
24,000 KB
testcase_95 AC 229 ms
23,424 KB
testcase_96 AC 220 ms
24,156 KB
testcase_97 AC 225 ms
24,168 KB
testcase_98 AC 193 ms
23,856 KB
testcase_99 AC 178 ms
24,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef hari64
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define debug(...)
#else
#include "util/viewer.hpp"
#define debug(...) viewer::_debug(__LINE__, #__VA_ARGS__, __VA_ARGS__)
#endif
// clang-format off
using namespace std;
using ll = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<ll, ll>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vc<T>>;
template <typename T> using vvvc = vector<vvc<T>>;
using vi = vc<int>; using vl = vc<ll>; using vpi = vc<pii>; using vpl = vc<pll>;
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(), (x).rend()
constexpr int INF = 1001001001; constexpr long long INFll = 1001001001001001001;
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
// clang-format on

struct Enemy {
    int h, p;
    int x, y;
    int initH;
    Enemy(int h, int p, int x) : h(h), p(p), x(x), y(59) { initH = h; }
};

constexpr int H = 60;
constexpr int W = 25;
vvc<Enemy> GRID(W);
int NOW_X;
int LEVEL;
int POWER_SUM;
int SCORE;

void update(vvc<Enemy>& g) {
    for (int x = 0; x < W; x++) {
        if (g[x].empty()) continue;
        for (auto& e : g[x]) {
            e.y--;
        }
        if (g[x].back().y == -1) {
            g[x].pop_back();
        }
        assert(g[x].empty() || g[x].back().y != -1);
    }
}

tuple<int, int, string> simulate(vector<int>& enemy) {
    string moves = "";
    int score = 0;
    int score2 = 0;
    int nowX = NOW_X;
    int level = LEVEL;
    int powerSum = POWER_SUM;
    int totalTurn = 0;
    int enemyIndex = 0;

    auto grid = GRID;
    // for (int x = 0; x < W; x++) {
    //     set<int> check;
    //     for (auto& e : grid[x]) {
    //         check.insert(e.y);
    //     }
    //     assert(check.size() == grid[x].size());
    // }

    while (true) {
        totalTurn++;
        if (totalTurn > 1000) break;

        string move = "S";
        if (nowX < enemy[enemyIndex]) {
            if (enemy[enemyIndex] - nowX < 12) {
                move = "R";
            } else {
                move = "L";
            }
        } else if (nowX > enemy[enemyIndex]) {
            if (nowX - enemy[enemyIndex] < 12) {
                move = "L";
            } else {
                move = "R";
            }
        }
        if (enemyIndex < 1) {
            moves += move;
        }

        if (move == "L") nowX = (25 + nowX - 1) % 25;
        if (move == "R") nowX = (25 + nowX + 1) % 25;
        if (move == "S") nowX = nowX;

        if (grid[nowX].empty()) continue;
        if (grid[nowX].back().y <= 1) {
            return {-INF, -INF, "S"};
        }
        grid[nowX].back().h -= level;

        score2 += grid[nowX].back().initH;
        if (grid[nowX].back().h <= 0) {
            score += grid[nowX].back().initH;
            powerSum += grid[nowX].back().p;
            level = 1 + powerSum / 100;
            grid[nowX].pop_back();
            while (enemyIndex < int(enemy.size()) && grid[enemy[enemyIndex]].empty()) {
                enemyIndex++;
            }
            if (enemyIndex >= int(enemy.size())) break;
        }

        update(grid);
    }

    return {score / totalTurn, score2, moves};
}

string solve() {
    int bestScore = -1;
    string bestMove = "S";
    if (LEVEL <= 150) {
        for (int e1 = 0; e1 < W; e1++) {
            if (GRID[e1].empty()) continue;
            vi enemies = {e1};
            auto [score, _, move] = simulate(enemies);
            if (chmax(bestScore, score)) {
                bestMove = move;
            }
        }
    } else {
        for (int e1 = 0; e1 < W; e1++) {
            if (GRID[e1].empty()) continue;
            for (int e2 = 0; e2 < W; e2++) {
                if (GRID[e2].empty()) continue;
                vi enemies = {e1, e2};
                auto [score, _, move] = simulate(enemies);
                if (chmax(bestScore, score)) {
                    bestMove = move;
                }
            }
        }
    }
    if (bestScore == -1) {
        debug("Game Over?");
        bestMove = "S";
    }
    // assert(!bestMove.empty());
    // debug(bestScore, bestMove);
    return bestMove;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

#ifdef hari64
    for (int _ = 0; _ < W; _++) {
        int p;
        cin >> p;
        assert(1 <= p && p <= 8);
    }
#endif

    NOW_X = 12;
    LEVEL = 1;
    POWER_SUM = 0;
    SCORE = 0;

    const int NUM_OF_TURNS = 1000;

    string moves = "";
    vector<string> ans;

    for (int i = 0; i < NUM_OF_TURNS; i++) {
        // debug(i);
        update(GRID);

        int n;
        cin >> n;
        if (n == -1) break;

        for (int i = 0; i < n; i++) {
            int h, p, x;
            cin >> h >> p >> x;
            assert(GRID[x].empty() || GRID[x].front().y < 59);
            GRID[x].insert(GRID[x].begin(), Enemy(h, p, x));
        }

        string s;
        if (i <= 5) {
            s = "S";
        } else if (i <= 40) {
            if (moves.size() == 0) {
                moves = solve();
            }
            s = string(1, moves[0]);
            moves.erase(moves.begin());
        } else {
            s = string(1, solve()[0]);
        }

#ifndef hari64
        cout << s << endl;
        flush(cout);
#endif
        ans.push_back(s);

        if (s == "L") NOW_X = (25 + NOW_X - 1) % 25;
        if (s == "R") NOW_X = (25 + NOW_X + 1) % 25;
        if (s == "S") NOW_X = NOW_X;

        if (GRID[NOW_X].empty()) continue;
        GRID[NOW_X].back().h -= LEVEL;
        if (GRID[NOW_X].back().h <= 0) {
            SCORE += GRID[NOW_X].back().initH;
            POWER_SUM += GRID[NOW_X].back().p;
            LEVEL = 1 + POWER_SUM / 100;
            GRID[NOW_X].pop_back();
        }
    }

    debug(SCORE, LEVEL, POWER_SUM, NOW_X);

#ifdef hari64
    for (auto s : ans) {
        cout << s << endl;
    }
#endif

    return 0;
}
0