結果
問題 | No.5017 Tool-assisted Shooting |
ユーザー | shell_mug |
提出日時 | 2023-07-16 19:06:40 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 8,916 bytes |
コンパイル時間 | 2,294 ms |
コンパイル使用メモリ | 156,480 KB |
実行使用メモリ | 24,420 KB |
スコア | 3,766,452 |
平均クエリ数 | 1000.00 |
最終ジャッジ日時 | 2023-07-16 19:07:41 |
合計ジャッジ時間 | 15,182 ms |
ジャッジサーバーID (参考情報) |
judge9 / judge12 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
24,276 KB |
testcase_01 | AC | 69 ms
24,012 KB |
testcase_02 | AC | 68 ms
24,024 KB |
testcase_03 | AC | 68 ms
24,336 KB |
testcase_04 | AC | 68 ms
23,376 KB |
testcase_05 | AC | 68 ms
23,832 KB |
testcase_06 | AC | 67 ms
23,364 KB |
testcase_07 | AC | 69 ms
24,360 KB |
testcase_08 | AC | 67 ms
23,616 KB |
testcase_09 | AC | 66 ms
23,808 KB |
testcase_10 | AC | 79 ms
24,324 KB |
testcase_11 | AC | 69 ms
23,820 KB |
testcase_12 | AC | 68 ms
24,024 KB |
testcase_13 | AC | 68 ms
23,376 KB |
testcase_14 | AC | 68 ms
24,024 KB |
testcase_15 | AC | 68 ms
23,388 KB |
testcase_16 | AC | 69 ms
24,024 KB |
testcase_17 | AC | 68 ms
24,324 KB |
testcase_18 | AC | 68 ms
24,276 KB |
testcase_19 | AC | 68 ms
23,664 KB |
testcase_20 | AC | 70 ms
23,664 KB |
testcase_21 | AC | 70 ms
24,252 KB |
testcase_22 | AC | 97 ms
24,360 KB |
testcase_23 | AC | 69 ms
23,556 KB |
testcase_24 | AC | 69 ms
24,024 KB |
testcase_25 | AC | 69 ms
24,000 KB |
testcase_26 | AC | 70 ms
24,024 KB |
testcase_27 | AC | 70 ms
23,844 KB |
testcase_28 | AC | 68 ms
23,496 KB |
testcase_29 | AC | 68 ms
23,352 KB |
testcase_30 | AC | 67 ms
23,352 KB |
testcase_31 | AC | 67 ms
23,664 KB |
testcase_32 | AC | 66 ms
24,384 KB |
testcase_33 | AC | 67 ms
23,388 KB |
testcase_34 | AC | 68 ms
23,820 KB |
testcase_35 | AC | 68 ms
23,544 KB |
testcase_36 | AC | 66 ms
23,652 KB |
testcase_37 | AC | 69 ms
23,820 KB |
testcase_38 | AC | 68 ms
23,520 KB |
testcase_39 | AC | 67 ms
24,312 KB |
testcase_40 | AC | 66 ms
23,424 KB |
testcase_41 | AC | 66 ms
23,652 KB |
testcase_42 | AC | 70 ms
23,664 KB |
testcase_43 | AC | 68 ms
24,024 KB |
testcase_44 | AC | 69 ms
23,412 KB |
testcase_45 | AC | 69 ms
23,532 KB |
testcase_46 | AC | 71 ms
24,036 KB |
testcase_47 | AC | 68 ms
23,508 KB |
testcase_48 | AC | 69 ms
23,652 KB |
testcase_49 | AC | 68 ms
23,616 KB |
testcase_50 | AC | 68 ms
23,412 KB |
testcase_51 | AC | 70 ms
23,544 KB |
testcase_52 | AC | 71 ms
23,400 KB |
testcase_53 | AC | 71 ms
23,400 KB |
testcase_54 | AC | 71 ms
23,400 KB |
testcase_55 | AC | 68 ms
23,388 KB |
testcase_56 | AC | 68 ms
24,336 KB |
testcase_57 | AC | 69 ms
23,544 KB |
testcase_58 | AC | 69 ms
24,000 KB |
testcase_59 | AC | 69 ms
24,264 KB |
testcase_60 | AC | 68 ms
23,364 KB |
testcase_61 | AC | 70 ms
23,856 KB |
testcase_62 | AC | 69 ms
24,024 KB |
testcase_63 | AC | 69 ms
24,312 KB |
testcase_64 | AC | 98 ms
23,808 KB |
testcase_65 | AC | 70 ms
24,036 KB |
testcase_66 | AC | 69 ms
23,616 KB |
testcase_67 | AC | 69 ms
24,420 KB |
testcase_68 | AC | 69 ms
23,640 KB |
testcase_69 | AC | 70 ms
23,988 KB |
testcase_70 | AC | 72 ms
23,508 KB |
testcase_71 | AC | 69 ms
23,412 KB |
testcase_72 | AC | 68 ms
23,544 KB |
testcase_73 | AC | 70 ms
23,496 KB |
testcase_74 | AC | 68 ms
23,640 KB |
testcase_75 | AC | 68 ms
24,348 KB |
testcase_76 | AC | 71 ms
23,508 KB |
testcase_77 | AC | 70 ms
24,336 KB |
testcase_78 | AC | 70 ms
23,412 KB |
testcase_79 | AC | 69 ms
24,012 KB |
testcase_80 | AC | 68 ms
24,012 KB |
testcase_81 | AC | 68 ms
23,376 KB |
testcase_82 | AC | 69 ms
23,844 KB |
testcase_83 | AC | 67 ms
23,412 KB |
testcase_84 | AC | 69 ms
23,436 KB |
testcase_85 | AC | 73 ms
23,628 KB |
testcase_86 | AC | 69 ms
23,340 KB |
testcase_87 | AC | 68 ms
23,364 KB |
testcase_88 | AC | 69 ms
23,664 KB |
testcase_89 | AC | 73 ms
24,000 KB |
testcase_90 | AC | 69 ms
23,364 KB |
testcase_91 | AC | 70 ms
24,012 KB |
testcase_92 | AC | 69 ms
23,376 KB |
testcase_93 | AC | 69 ms
24,372 KB |
testcase_94 | AC | 68 ms
23,844 KB |
testcase_95 | AC | 69 ms
23,604 KB |
testcase_96 | AC | 70 ms
24,024 KB |
testcase_97 | AC | 70 ms
23,604 KB |
testcase_98 | AC | 69 ms
23,544 KB |
testcase_99 | AC | 69 ms
23,604 KB |
コンパイルメッセージ
コピーコンストラクタ ‘Input::Input(const Input&)’ 内, inlined from ‘Solver::Solver(const Input&)’ at main.cpp:269:33, inlined from ‘int main()’ at main.cpp:343:24: main.cpp:78:8: 警告: ‘input.Input::p’ is used uninitialized [-Wuninitialized] 78 | struct Input { | ^~~~~ main.cpp: 関数 ‘int main()’ 内: main.cpp:341:11: 備考: ‘input’ はここで宣言されています 341 | Input input; | ^~~~~
ソースコード
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #include <stack> #include <functional> #include <fstream> // #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; double max_cospa = -INFINITY; 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 hp = get<1>(grid[(offset + dx) % h][y]), lv = 1 + s / 100; double cospa; if (y == player) { cospa = (double)hp / ((hp + lv - 1) / lv); } else { int d = get_distance(y, player); int cur_hp = get<1>(grid[(offset + dx) % h][player]); int prev_turns = (get<1>(grid[(offset + dx) % h][player]) - get<0>(grid[(offset + dx) % h][player])) / lv; cospa = (double)hp / ((hp + lv - 1) / lv + d + prev_turns); } // = (double)hp / (d + (hp + nec_turns)); if (best_y == -1 || cospa > max_cospa) { best_y = y; max_cospa = cospa; } // 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; }