結果

問題 No.5017 Tool-assisted Shooting
ユーザー eijiroueijirou
提出日時 2023-07-16 16:02:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 5,944 bytes
コンパイル時間 3,420 ms
コンパイル使用メモリ 227,880 KB
実行使用メモリ 24,408 KB
スコア 74,830
平均クエリ数 399.74
最終ジャッジ日時 2023-07-16 16:02:23
合計ジャッジ時間 11,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
23,844 KB
testcase_01 AC 61 ms
23,640 KB
testcase_02 AC 28 ms
24,360 KB
testcase_03 AC 27 ms
23,424 KB
testcase_04 AC 36 ms
23,412 KB
testcase_05 AC 35 ms
23,544 KB
testcase_06 AC 28 ms
23,664 KB
testcase_07 AC 37 ms
24,408 KB
testcase_08 AC 29 ms
23,976 KB
testcase_09 AC 33 ms
23,544 KB
testcase_10 AC 38 ms
23,628 KB
testcase_11 AC 30 ms
23,832 KB
testcase_12 AC 27 ms
23,832 KB
testcase_13 AC 32 ms
24,408 KB
testcase_14 AC 31 ms
23,556 KB
testcase_15 AC 29 ms
23,652 KB
testcase_16 AC 28 ms
24,300 KB
testcase_17 AC 60 ms
23,376 KB
testcase_18 AC 60 ms
23,544 KB
testcase_19 AC 35 ms
24,348 KB
testcase_20 AC 34 ms
23,712 KB
testcase_21 AC 33 ms
23,424 KB
testcase_22 AC 39 ms
23,388 KB
testcase_23 AC 28 ms
23,424 KB
testcase_24 AC 37 ms
24,264 KB
testcase_25 AC 31 ms
23,844 KB
testcase_26 AC 39 ms
23,544 KB
testcase_27 AC 59 ms
23,424 KB
testcase_28 AC 32 ms
23,628 KB
testcase_29 AC 31 ms
24,372 KB
testcase_30 AC 37 ms
24,012 KB
testcase_31 AC 28 ms
24,036 KB
testcase_32 AC 31 ms
24,348 KB
testcase_33 AC 31 ms
23,856 KB
testcase_34 AC 60 ms
23,856 KB
testcase_35 AC 29 ms
24,048 KB
testcase_36 AC 40 ms
23,640 KB
testcase_37 AC 33 ms
23,664 KB
testcase_38 AC 27 ms
24,276 KB
testcase_39 AC 60 ms
23,556 KB
testcase_40 AC 36 ms
23,844 KB
testcase_41 AC 28 ms
23,664 KB
testcase_42 AC 46 ms
24,048 KB
testcase_43 AC 47 ms
23,664 KB
testcase_44 AC 27 ms
24,276 KB
testcase_45 AC 31 ms
23,436 KB
testcase_46 AC 59 ms
23,640 KB
testcase_47 AC 32 ms
24,276 KB
testcase_48 AC 59 ms
23,412 KB
testcase_49 AC 59 ms
24,024 KB
testcase_50 AC 31 ms
24,036 KB
testcase_51 AC 64 ms
24,264 KB
testcase_52 AC 60 ms
23,388 KB
testcase_53 AC 34 ms
24,072 KB
testcase_54 AC 30 ms
24,060 KB
testcase_55 AC 42 ms
23,388 KB
testcase_56 AC 28 ms
23,436 KB
testcase_57 AC 59 ms
23,844 KB
testcase_58 AC 50 ms
24,348 KB
testcase_59 AC 29 ms
24,036 KB
testcase_60 AC 44 ms
23,412 KB
testcase_61 AC 60 ms
24,048 KB
testcase_62 AC 59 ms
24,396 KB
testcase_63 AC 34 ms
24,360 KB
testcase_64 AC 31 ms
23,544 KB
testcase_65 AC 63 ms
23,388 KB
testcase_66 AC 35 ms
24,384 KB
testcase_67 AC 32 ms
23,856 KB
testcase_68 AC 39 ms
23,388 KB
testcase_69 AC 34 ms
23,664 KB
testcase_70 AC 28 ms
23,652 KB
testcase_71 AC 37 ms
24,264 KB
testcase_72 AC 29 ms
23,388 KB
testcase_73 AC 60 ms
23,388 KB
testcase_74 AC 32 ms
23,388 KB
testcase_75 AC 30 ms
24,036 KB
testcase_76 AC 33 ms
23,556 KB
testcase_77 AC 32 ms
23,832 KB
testcase_78 AC 33 ms
23,904 KB
testcase_79 AC 41 ms
24,336 KB
testcase_80 AC 31 ms
24,036 KB
testcase_81 AC 34 ms
23,556 KB
testcase_82 AC 34 ms
24,372 KB
testcase_83 AC 31 ms
23,664 KB
testcase_84 AC 29 ms
23,664 KB
testcase_85 AC 27 ms
24,024 KB
testcase_86 AC 32 ms
23,628 KB
testcase_87 AC 29 ms
23,388 KB
testcase_88 AC 28 ms
23,664 KB
testcase_89 AC 32 ms
23,640 KB
testcase_90 AC 32 ms
23,844 KB
testcase_91 AC 28 ms
23,556 KB
testcase_92 AC 58 ms
23,388 KB
testcase_93 AC 28 ms
23,388 KB
testcase_94 AC 32 ms
23,676 KB
testcase_95 AC 60 ms
23,388 KB
testcase_96 AC 49 ms
23,388 KB
testcase_97 AC 28 ms
23,424 KB
testcase_98 AC 33 ms
24,336 KB
testcase_99 AC 30 ms
24,336 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
コピーコンストラクタ ‘Input::Input(const Input&)’ 内,
    inlined from ‘Solver::Solver(const Input&)’ at main.cpp:181:33,
    inlined from ‘int main()’ at main.cpp:239:24:
main.cpp:56:8: 警告: ‘input.Input::p’ is used uninitialized [-Wuninitialized]
   56 | struct Input {
      |        ^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:237:11: 備考: ‘input’ はここで宣言されています
  237 |     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_oppenents_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;
        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;
    }
};

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_oppenents_appear(input.interact());


            int dy = 0;


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

    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 = 10;
    // multi_test(cases);

    return 0;
}
0