結果
問題 | No.5017 Tool-assisted Shooting |
ユーザー | eijirou |
提出日時 | 2023-07-16 17:57:37 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 7,662 bytes |
コンパイル時間 | 3,871 ms |
コンパイル使用メモリ | 229,260 KB |
実行使用メモリ | 24,432 KB |
スコア | 3,791,450 |
平均クエリ数 | 1000.00 |
最終ジャッジ日時 | 2023-07-16 17:58:04 |
合計ジャッジ時間 | 24,532 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
testcase_50 | RE | - |
testcase_51 | RE | - |
testcase_52 | RE | - |
testcase_53 | RE | - |
testcase_54 | RE | - |
testcase_55 | RE | - |
testcase_56 | RE | - |
testcase_57 | RE | - |
testcase_58 | RE | - |
testcase_59 | RE | - |
testcase_60 | RE | - |
testcase_61 | RE | - |
testcase_62 | RE | - |
testcase_63 | RE | - |
testcase_64 | RE | - |
testcase_65 | RE | - |
testcase_66 | RE | - |
testcase_67 | RE | - |
testcase_68 | RE | - |
testcase_69 | RE | - |
testcase_70 | RE | - |
testcase_71 | RE | - |
testcase_72 | RE | - |
testcase_73 | RE | - |
testcase_74 | RE | - |
testcase_75 | RE | - |
testcase_76 | RE | - |
testcase_77 | RE | - |
testcase_78 | RE | - |
testcase_79 | RE | - |
testcase_80 | RE | - |
testcase_81 | RE | - |
testcase_82 | RE | - |
testcase_83 | RE | - |
testcase_84 | RE | - |
testcase_85 | RE | - |
testcase_86 | RE | - |
testcase_87 | RE | - |
testcase_88 | RE | - |
testcase_89 | RE | - |
testcase_90 | RE | - |
testcase_91 | RE | - |
testcase_92 | RE | - |
testcase_93 | RE | - |
testcase_94 | RE | - |
testcase_95 | RE | - |
testcase_96 | RE | - |
testcase_97 | RE | - |
testcase_98 | RE | - |
testcase_99 | RE | - |
コンパイルメッセージ
コピーコンストラクタ ‘Input::Input(const Input&)’ 内, inlined from ‘Solver::Solver(const Input&)’ at main.cpp:231: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; 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); if (best_y == -1 || d < min_d) { best_y = y; min_d = d; } } } 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; 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; }