結果
問題 | No.5017 Tool-assisted Shooting |
ユーザー | eijirou |
提出日時 | 2023-07-16 17:52:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 72 ms / 2,000 ms |
コード長 | 7,714 bytes |
コンパイル時間 | 3,460 ms |
コンパイル使用メモリ | 229,348 KB |
実行使用メモリ | 24,288 KB |
スコア | 3,677,959 |
平均クエリ数 | 985.13 |
最終ジャッジ日時 | 2023-07-16 17:52:34 |
合計ジャッジ時間 | 14,689 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
23,796 KB |
testcase_01 | AC | 64 ms
23,556 KB |
testcase_02 | AC | 64 ms
23,856 KB |
testcase_03 | AC | 64 ms
23,472 KB |
testcase_04 | AC | 71 ms
23,556 KB |
testcase_05 | AC | 64 ms
23,544 KB |
testcase_06 | AC | 65 ms
23,472 KB |
testcase_07 | AC | 65 ms
24,060 KB |
testcase_08 | AC | 65 ms
23,556 KB |
testcase_09 | AC | 64 ms
23,388 KB |
testcase_10 | AC | 64 ms
23,556 KB |
testcase_11 | AC | 65 ms
23,796 KB |
testcase_12 | AC | 65 ms
23,388 KB |
testcase_13 | AC | 65 ms
23,856 KB |
testcase_14 | AC | 65 ms
24,180 KB |
testcase_15 | AC | 65 ms
24,024 KB |
testcase_16 | AC | 65 ms
24,108 KB |
testcase_17 | AC | 65 ms
23,556 KB |
testcase_18 | AC | 65 ms
23,388 KB |
testcase_19 | AC | 65 ms
23,868 KB |
testcase_20 | AC | 64 ms
24,120 KB |
testcase_21 | AC | 65 ms
24,048 KB |
testcase_22 | AC | 64 ms
23,412 KB |
testcase_23 | AC | 65 ms
23,472 KB |
testcase_24 | AC | 69 ms
24,252 KB |
testcase_25 | AC | 65 ms
23,448 KB |
testcase_26 | AC | 65 ms
24,192 KB |
testcase_27 | AC | 64 ms
23,652 KB |
testcase_28 | AC | 67 ms
23,688 KB |
testcase_29 | AC | 64 ms
23,376 KB |
testcase_30 | AC | 64 ms
24,252 KB |
testcase_31 | AC | 69 ms
23,856 KB |
testcase_32 | AC | 65 ms
23,568 KB |
testcase_33 | AC | 64 ms
23,364 KB |
testcase_34 | AC | 65 ms
23,568 KB |
testcase_35 | AC | 65 ms
23,448 KB |
testcase_36 | AC | 64 ms
23,544 KB |
testcase_37 | AC | 65 ms
23,652 KB |
testcase_38 | AC | 65 ms
24,252 KB |
testcase_39 | AC | 64 ms
23,592 KB |
testcase_40 | AC | 65 ms
23,376 KB |
testcase_41 | AC | 64 ms
24,048 KB |
testcase_42 | AC | 46 ms
23,532 KB |
testcase_43 | AC | 65 ms
24,156 KB |
testcase_44 | AC | 65 ms
23,472 KB |
testcase_45 | AC | 54 ms
24,048 KB |
testcase_46 | AC | 65 ms
23,328 KB |
testcase_47 | AC | 65 ms
23,364 KB |
testcase_48 | AC | 65 ms
24,168 KB |
testcase_49 | AC | 65 ms
24,180 KB |
testcase_50 | AC | 66 ms
23,424 KB |
testcase_51 | AC | 65 ms
23,472 KB |
testcase_52 | AC | 66 ms
23,868 KB |
testcase_53 | AC | 66 ms
23,676 KB |
testcase_54 | AC | 65 ms
23,664 KB |
testcase_55 | AC | 66 ms
23,796 KB |
testcase_56 | AC | 67 ms
23,388 KB |
testcase_57 | AC | 65 ms
24,180 KB |
testcase_58 | AC | 65 ms
24,288 KB |
testcase_59 | AC | 65 ms
24,180 KB |
testcase_60 | AC | 66 ms
24,060 KB |
testcase_61 | AC | 69 ms
23,676 KB |
testcase_62 | AC | 67 ms
23,472 KB |
testcase_63 | AC | 66 ms
24,048 KB |
testcase_64 | AC | 65 ms
23,820 KB |
testcase_65 | AC | 66 ms
24,036 KB |
testcase_66 | AC | 65 ms
23,640 KB |
testcase_67 | AC | 66 ms
23,652 KB |
testcase_68 | AC | 66 ms
23,328 KB |
testcase_69 | AC | 65 ms
24,240 KB |
testcase_70 | AC | 66 ms
24,240 KB |
testcase_71 | AC | 67 ms
23,784 KB |
testcase_72 | AC | 65 ms
23,412 KB |
testcase_73 | AC | 65 ms
23,796 KB |
testcase_74 | AC | 65 ms
23,880 KB |
testcase_75 | AC | 67 ms
23,436 KB |
testcase_76 | AC | 37 ms
24,168 KB |
testcase_77 | AC | 66 ms
23,388 KB |
testcase_78 | AC | 66 ms
23,556 KB |
testcase_79 | AC | 65 ms
23,652 KB |
testcase_80 | AC | 71 ms
24,036 KB |
testcase_81 | AC | 65 ms
23,340 KB |
testcase_82 | AC | 65 ms
23,784 KB |
testcase_83 | AC | 65 ms
23,436 KB |
testcase_84 | AC | 66 ms
23,484 KB |
testcase_85 | AC | 65 ms
23,328 KB |
testcase_86 | AC | 65 ms
24,180 KB |
testcase_87 | AC | 65 ms
23,556 KB |
testcase_88 | AC | 66 ms
23,388 KB |
testcase_89 | AC | 65 ms
23,472 KB |
testcase_90 | AC | 66 ms
24,240 KB |
testcase_91 | AC | 65 ms
23,856 KB |
testcase_92 | AC | 65 ms
23,472 KB |
testcase_93 | AC | 66 ms
24,156 KB |
testcase_94 | AC | 65 ms
23,556 KB |
testcase_95 | AC | 66 ms
24,156 KB |
testcase_96 | AC | 65 ms
23,448 KB |
testcase_97 | AC | 65 ms
23,868 KB |
testcase_98 | AC | 65 ms
23,580 KB |
testcase_99 | AC | 70 ms
23,652 KB |
コンパイルメッセージ
コピーコンストラクタ ‘Input::Input(const Input&)’ 内, inlined from ‘Solver::Solver(const Input&)’ at main.cpp:234:33, inlined from ‘int main()’ at main.cpp:305:24: main.cpp:56:8: 警告: ‘input.Input::p’ is used uninitialized [-Wuninitialized] 56 | struct Input { | ^~~~~ main.cpp: 関数 ‘int main()’ 内: main.cpp:303:11: 備考: ‘input’ はここで宣言されています 303 | Input input; | ^~~~~
ソースコード
#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; int min_d = -1; int power = -1; for (int y = 0; y < w; ++y) { int dx = get_lowest_opponent(y); if (dx == -1) { continue; } if (can_destroy(dx, y)) { int d = get_distance(y, player); int p = get<2>(grid[(offset + dx) % h][y]); if (best_y == -1 || d < min_d || (d == min_d && p > power)) { best_y = y; min_d = d; power = p; } } } 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; }