結果

問題 No.5017 Tool-assisted Shooting
ユーザー eijiroueijirou
提出日時 2023-07-16 17:41:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 7,511 bytes
コンパイル時間 4,523 ms
コンパイル使用メモリ 228,892 KB
実行使用メモリ 24,360 KB
スコア 3,696,127
平均クエリ数 984.34
最終ジャッジ日時 2023-07-16 17:41:24
合計ジャッジ時間 14,565 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
23,616 KB
testcase_01 AC 67 ms
23,412 KB
testcase_02 AC 66 ms
23,676 KB
testcase_03 AC 67 ms
23,556 KB
testcase_04 AC 67 ms
24,000 KB
testcase_05 AC 67 ms
23,844 KB
testcase_06 AC 67 ms
23,376 KB
testcase_07 AC 67 ms
23,412 KB
testcase_08 AC 75 ms
23,424 KB
testcase_09 AC 66 ms
24,360 KB
testcase_10 AC 67 ms
23,664 KB
testcase_11 AC 67 ms
23,376 KB
testcase_12 AC 67 ms
23,604 KB
testcase_13 AC 67 ms
24,000 KB
testcase_14 AC 67 ms
24,360 KB
testcase_15 AC 67 ms
23,604 KB
testcase_16 AC 67 ms
23,988 KB
testcase_17 AC 68 ms
23,988 KB
testcase_18 AC 68 ms
23,664 KB
testcase_19 AC 67 ms
23,256 KB
testcase_20 AC 68 ms
23,328 KB
testcase_21 AC 67 ms
24,036 KB
testcase_22 AC 58 ms
23,352 KB
testcase_23 AC 66 ms
23,592 KB
testcase_24 AC 66 ms
23,580 KB
testcase_25 AC 65 ms
23,556 KB
testcase_26 AC 65 ms
23,424 KB
testcase_27 AC 35 ms
23,616 KB
testcase_28 AC 66 ms
23,352 KB
testcase_29 AC 67 ms
24,048 KB
testcase_30 AC 66 ms
23,376 KB
testcase_31 AC 65 ms
23,508 KB
testcase_32 AC 66 ms
24,312 KB
testcase_33 AC 66 ms
24,360 KB
testcase_34 AC 76 ms
23,244 KB
testcase_35 AC 65 ms
24,348 KB
testcase_36 AC 65 ms
23,352 KB
testcase_37 AC 67 ms
23,988 KB
testcase_38 AC 66 ms
23,712 KB
testcase_39 AC 65 ms
23,796 KB
testcase_40 AC 65 ms
23,436 KB
testcase_41 AC 66 ms
24,360 KB
testcase_42 AC 67 ms
23,604 KB
testcase_43 AC 67 ms
24,348 KB
testcase_44 AC 67 ms
23,604 KB
testcase_45 AC 67 ms
23,976 KB
testcase_46 AC 71 ms
23,532 KB
testcase_47 AC 67 ms
23,532 KB
testcase_48 AC 67 ms
23,388 KB
testcase_49 AC 67 ms
24,264 KB
testcase_50 AC 67 ms
24,048 KB
testcase_51 AC 67 ms
23,484 KB
testcase_52 AC 67 ms
23,376 KB
testcase_53 AC 67 ms
24,348 KB
testcase_54 AC 68 ms
23,376 KB
testcase_55 AC 69 ms
23,652 KB
testcase_56 AC 68 ms
23,556 KB
testcase_57 AC 67 ms
23,616 KB
testcase_58 AC 83 ms
23,424 KB
testcase_59 AC 67 ms
23,340 KB
testcase_60 AC 66 ms
24,348 KB
testcase_61 AC 67 ms
23,328 KB
testcase_62 AC 67 ms
23,376 KB
testcase_63 AC 68 ms
23,364 KB
testcase_64 AC 68 ms
24,060 KB
testcase_65 AC 68 ms
23,388 KB
testcase_66 AC 67 ms
23,628 KB
testcase_67 AC 67 ms
24,336 KB
testcase_68 AC 68 ms
24,060 KB
testcase_69 AC 74 ms
23,532 KB
testcase_70 AC 68 ms
23,664 KB
testcase_71 AC 67 ms
24,204 KB
testcase_72 AC 67 ms
23,412 KB
testcase_73 AC 68 ms
23,628 KB
testcase_74 AC 67 ms
23,988 KB
testcase_75 AC 67 ms
23,424 KB
testcase_76 AC 66 ms
23,976 KB
testcase_77 AC 67 ms
24,048 KB
testcase_78 AC 67 ms
23,796 KB
testcase_79 AC 66 ms
23,388 KB
testcase_80 AC 65 ms
24,216 KB
testcase_81 AC 67 ms
24,300 KB
testcase_82 AC 66 ms
23,616 KB
testcase_83 AC 65 ms
24,324 KB
testcase_84 AC 66 ms
23,496 KB
testcase_85 AC 66 ms
24,336 KB
testcase_86 AC 66 ms
23,652 KB
testcase_87 AC 41 ms
23,388 KB
testcase_88 AC 66 ms
24,336 KB
testcase_89 AC 66 ms
23,640 KB
testcase_90 AC 67 ms
23,544 KB
testcase_91 AC 67 ms
23,976 KB
testcase_92 AC 68 ms
23,424 KB
testcase_93 AC 67 ms
23,400 KB
testcase_94 AC 101 ms
23,388 KB
testcase_95 AC 68 ms
24,216 KB
testcase_96 AC 66 ms
24,300 KB
testcase_97 AC 68 ms
24,300 KB
testcase_98 AC 66 ms
23,988 KB
testcase_99 AC 67 ms
23,796 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
コピーコンストラクタ ‘Input::Input(const Input&)’ 内,
    inlined from ‘Solver::Solver(const Input&)’ at main.cpp:228:33,
    inlined from ‘int main()’ at main.cpp:299:24:
main.cpp:56:8: 警告: ‘input.Input::p’ is used uninitialized [-Wuninitialized]
   56 | struct Input {
      |        ^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:297:11: 備考: ‘input’ はここで宣言されています
  297 |     Input input;
      |           ^~~~~

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define ll long long int
#define ull unsigned long long int

uniform_real_distribution<> uniform(0.0, 1.0);

struct Timer {
    chrono::system_clock::time_point start;

    void begin() {
        start = chrono::system_clock::now();
    }

    double stopwatch() {
        chrono::system_clock::time_point end = chrono::system_clock::now();
        double elapsed = chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
        elapsed *= 1e-9; // nanoseconds -> seconds
        return elapsed;
    }

    bool yet(double time_limit) {
        return stopwatch() < time_limit;
    }

    double progress(double time_limit) {
        return stopwatch() / time_limit;
    }

    bool annealing_scheduler(double profit, mt19937& engine, double time_limit, double t0, double t1) {
        assert(0.0 <= t1 && t1 <= t0);
        if (profit >= 0.0) {
            return true;
        } else {
            double ratio = progress(time_limit);
            double t = pow(t0, 1.0 - ratio) * pow(t1, ratio);
            return uniform(engine) < pow(2.0, profit/t);
        }
    }
};

constexpr double time_limit = 1.95;
constexpr int h = 60;
constexpr int w = 25;
constexpr int w_center = 12;
constexpr int max_turn = 1000;
constexpr tuple<int,int,int> none = {0, 0, 0};

struct Input {
    bool online_judge = true;
    array<int,w> p;
    array<vector<tuple<int,int,int>>,max_turn> hpx;
    int turn = 0;

    void input(const string& filename) {
        online_judge = false;

        ifstream in(filename);
        assert(in);
        
        for (int y = 0; y < w; ++y) {
            in >> p[y];
        }
        for (int turn = 0; turn < max_turn; ++turn) {
            int n;
            in >> n;
            hpx[turn].resize(n);
            for (int i = 0; i < n; ++i) {
                int hi, pi, xi;
                in >> hi >> pi >> xi;
                hpx[turn][i] = {hi, pi, xi};
            }
        }
    }

    vector<tuple<int,int,int>> interact() {
        ++turn;
        if (online_judge) {
            int n;
            cin >> n;
            assert(n != -1);
            vector<tuple<int,int,int>> ret(n);
            for (int i = 0; i < n; ++i) {
                int hi, pi, xi;
                cin >> hi >> pi >> xi;
                ret[i] = {hi, pi, xi};
            }
            return ret;
        } else {
            return hpx[turn - 1];
        }
    }

    void print(int dy) {
        assert(-1 <= dy && dy <= 1);
        if (online_judge) {
            cout << "LSR"[dy + 1] << endl;
        }
    }
};

struct State {
    int offset;
    int player;
    array<array<tuple<int,int,int>,w>,h> grid; // {temporary HP, initial HP, power}
    int s;
    int score;

    State() {
        offset = 0;
        player = w_center;
        for (int x = 0; x < h; ++x) {
            fill(grid[x].begin(), grid[x].end(), none);
        }
        s = 0;
        score = 0;
    }

    bool move_opponents() {
        assert(grid[offset][player] == none);
        if (grid[(offset + 1) % h][player] != none) {
            // game over
            return true;
        }
        fill(grid[offset].begin(), grid[offset].end(), none);
        ++offset;
        offset %= h;
        return false;
    }

    void make_opponents_appear(const vector<tuple<int,int,int>>& oppenents) {
        int x = (offset - 1 + h) % h;
        for (auto [hi, pi, yi] : oppenents) {
            grid[x][yi] = {hi, hi, pi};
        }
    }

    bool move_player(int dy) {
        assert(grid[offset][player] == none);
        player += dy;
        player += w;
        player %= w;
        return (grid[offset][player] != none);
    }

    void attack() {
        int dx = get_lowest_opponent(player);
        if (dx == -1) {
            return;
        }
        get<0>(grid[(offset + dx) % h][player]) -= 1 + s / 100;
        if (get<0>(grid[(offset + dx) % h][player]) <= 0) {
            // destroy the oppenent
            score += get<1>(grid[(offset + dx) % h][player]);
            s += get<2>(grid[(offset + dx) % h][player]);
            grid[(offset + dx) % h][player] = none;
        }
    }

    int get_lowest_opponent(int y) {
        for (int dx = 1; dx < h; ++dx) {
            if (grid[(offset + dx) % h][y] != none) {
                return dx;
            }
        }
        return -1;
    }

    int get_distance(int y0, int y1) {
        if (y0 < y1) {
            return min(y1 - y0, y0 + w - y1);
        } else {
            return min(y0 - y1, y1 + w - y0);
        }
    }

    int get_dy(int y) {
        if (y < player) {
            if (player - y < y + w - player) {
                return -1;
            } else {
                return 1;
            }
        } else if (y > player) {
            if (y - player < player + w - y) {
                return 1;
            } else {
                return -1;
            }
        } else {
            return 0;
        }
    }

    bool can_destroy(int dx, int y) {
        return (get<0>(grid[(offset + dx) % h][y]) + (1 + s / 100) - 1) / (1 + s / 100) <= dx - get_distance(y, player) - 1;
    }

    int greedy() {
        int best_y = -1;
        for (int y = 0; y < w; ++y) {
            int dx = get_lowest_opponent(y);
            if (dx == -1) {
                continue;
            }
            if (can_destroy(dx, y)) {
                if (best_y == -1 || get_distance(y, player) < get_distance(best_y, player)) {
                    best_y = y;
                }
            }
        }
        return (best_y == -1) ? 0 : get_dy(best_y);
    }
};

struct Solver {
    Timer timer;
    Input input;
    State state;

    Solver(const Input& input): input(input) {
        timer.begin();
    }

    void solve() {
        for (int turn = 0; turn < max_turn; ++turn) {
            if (state.move_opponents()) {
                break;
            }
            state.make_opponents_appear(input.interact());


            int dy = state.greedy();
            if (!can_move(dy)) {
                dy = (dy + 2) % 3 - 1;
            }

            input.print(dy);
            if (state.move_player(dy)) {
                break;
            }
            state.attack();
        }
    }

    bool can_move(int dy) {
        State s = state;
        if (s.move_player(dy)) {
            return false;
        }
        if (s.move_opponents()) {
            return false;
        }
        return true;
    }

    ll score() {
        return state.score;
    }
};

void multi_test(int cases) {
    cerr << "cases: " << cases << endl;

    long long sum_scores = 0.0;
    for (int seed = 0; seed < cases; ++seed) {
        string filename = "in/";
        filename += '0' + seed / 1000;
        filename += '0' + (seed / 100) % 10;
        filename += '0' + (seed / 10) % 10;
        filename += '0' + seed % 10;
        filename += ".txt";

        Timer timer;
        timer.begin();
 
        Input input;
        input.input(filename);
 
        Solver solver(input);
        solver.solve();

        cerr << filename << " " << solver.score() << " " << timer.stopwatch() << " sec" << endl;
        sum_scores += solver.score();
    }
    cerr << "Average Score: " << sum_scores / cases << endl;
}

int main() {
    Input input;

    Solver solver(input);
    solver.solve();

    // int cases = 100;
    // multi_test(cases);

    return 0;
}
0