結果
問題 | No.5016 Worst Mayor |
ユーザー | eijirou |
提出日時 | 2023-04-29 16:15:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 7,208 bytes |
コンパイル時間 | 5,538 ms |
コンパイル使用メモリ | 254,012 KB |
実行使用メモリ | 24,396 KB |
スコア | 17,053,783,728 |
平均クエリ数 | 368.00 |
最終ジャッジ日時 | 2023-04-29 16:16:51 |
合計ジャッジ時間 | 109,813 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,991 ms
24,276 KB |
testcase_01 | AC | 1,971 ms
23,640 KB |
testcase_02 | AC | 1,972 ms
24,060 KB |
testcase_03 | AC | 1,975 ms
24,288 KB |
testcase_04 | AC | 1,977 ms
24,000 KB |
testcase_05 | AC | 1,972 ms
23,472 KB |
testcase_06 | AC | 1,990 ms
24,000 KB |
testcase_07 | AC | 1,980 ms
24,396 KB |
testcase_08 | AC | 1,979 ms
23,568 KB |
testcase_09 | AC | 1,971 ms
23,976 KB |
testcase_10 | AC | 1,974 ms
23,892 KB |
testcase_11 | AC | 1,975 ms
23,652 KB |
testcase_12 | AC | 1,980 ms
24,264 KB |
testcase_13 | AC | 1,975 ms
24,336 KB |
testcase_14 | AC | 1,976 ms
23,412 KB |
testcase_15 | AC | 1,974 ms
23,532 KB |
testcase_16 | AC | 1,981 ms
23,988 KB |
testcase_17 | AC | 1,989 ms
24,312 KB |
testcase_18 | AC | 1,979 ms
23,388 KB |
testcase_19 | AC | 1,987 ms
23,388 KB |
testcase_20 | AC | 1,975 ms
24,240 KB |
testcase_21 | AC | 1,975 ms
24,072 KB |
testcase_22 | AC | 1,980 ms
23,616 KB |
testcase_23 | AC | 1,979 ms
24,192 KB |
testcase_24 | AC | 1,980 ms
23,664 KB |
testcase_25 | AC | 1,996 ms
24,264 KB |
testcase_26 | AC | 1,979 ms
23,988 KB |
testcase_27 | AC | 1,981 ms
23,640 KB |
testcase_28 | AC | 1,984 ms
24,000 KB |
testcase_29 | AC | 1,984 ms
24,108 KB |
testcase_30 | AC | 1,977 ms
23,976 KB |
testcase_31 | AC | 1,977 ms
23,520 KB |
testcase_32 | AC | 1,978 ms
23,592 KB |
testcase_33 | AC | 1,974 ms
23,412 KB |
testcase_34 | AC | 1,974 ms
24,288 KB |
testcase_35 | AC | 1,987 ms
23,412 KB |
testcase_36 | AC | 1,973 ms
23,832 KB |
testcase_37 | AC | 1,972 ms
24,108 KB |
testcase_38 | AC | 1,973 ms
24,048 KB |
testcase_39 | AC | 1,994 ms
23,700 KB |
testcase_40 | AC | 1,973 ms
24,000 KB |
testcase_41 | AC | 1,975 ms
23,412 KB |
testcase_42 | AC | 1,975 ms
23,448 KB |
testcase_43 | AC | 1,980 ms
23,652 KB |
testcase_44 | AC | 1,984 ms
23,652 KB |
testcase_45 | AC | 1,983 ms
23,652 KB |
testcase_46 | AC | 1,979 ms
23,616 KB |
testcase_47 | AC | 1,974 ms
24,180 KB |
testcase_48 | AC | 1,983 ms
24,252 KB |
testcase_49 | TLE | - |
ソースコード
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; struct Timer { chrono::system_clock::time_point start; double elapsed; void begin() { start = chrono::system_clock::now(); } double stopwatch() { chrono::system_clock::time_point end = chrono::system_clock::now(); elapsed = chrono::duration_cast<std::chrono::nanoseconds>(end - start).count(); elapsed *= 1e-9; // nanoseconds -> seconds return elapsed; } }; constexpr double time_limit = 1.9; constexpr int g = 14; constexpr int slow = 1000; constexpr int fast = 223; constexpr long long bonus = 50000; struct Input { int n, t; vector<pair<int,int>> ab, cd; void input() { cin >> n >> t; ab.resize(n); cd.resize(n); for (int i = 0; i < n; ++i) { int a, b, c, d; cin >> a >> b >> c >> d; ab[i] = {a - 1, b - 1}; cd[i] = {c - 1, d - 1}; } } }; long long expense(int people) { return floor(1e7 / sqrt(people)); } constexpr int inf = 1e9; constexpr int no_construction_turn = 300; constexpr int min_people = 30; constexpr int max_people = 100; constexpr int add_people = 20; struct Solver { Timer timer; int n, t; vector<pair<int,int>> ab, cd; vector<vector<bool>> h, v; long long money = 1000000; int people = 1; int income = 0; int constructions = 0; mt19937 engine = mt19937(0); Solver(const Input& input) { timer.begin(); n = input.n; t = input.t; ab = input.ab; cd = input.cd; h = vector<vector<bool>>(g, vector<bool>(g - 1, false)); v = vector<vector<bool>>(g - 1, vector<bool>(g, false)); } void solve() { for (int turn = 0; turn < t; ++turn) { //money += income; cin >> money >> people; if (turn >= no_construction_turn || timer.stopwatch() > time_limit) { cout << 3 << endl; money += bonus; } else if (money >= expense(people)) { auto [x, y, z, w] = choose_road(turn); if (x == -1) { cout << 3 << endl; money += bonus; continue; } cout << 1 << " " << x + 1 << " " << y + 1 << " " << z + 1 << " " << w + 1 << endl; ++constructions; money -= expense(people); income = calc_income(); } else if (people < min(max_people, min_people + add_people * constructions)) { cout << 2 << endl; ++people; } else { cout << 3 << endl; money += bonus; } } } vector<vector<int>> dijkstra(int sx, int sy) { vector<vector<int>> costs(g, vector<int>(g, inf)); costs[sx][sy] = 0; priority_queue<tuple<int,int,int>> todo; todo.push({0, sx, sy}); while (!todo.empty()) { auto [cost, x, y] = todo.top(); todo.pop(); cost = -cost; if (costs[x][y] < cost) { continue; } if (x > 0) { int c = v[x - 1][y] ? fast : slow; if (cost + c < costs[x - 1][y]) { costs[x - 1][y] = cost + c; todo.push({-(cost + c), x - 1, y}); } } if (x < g - 1) { int c = v[x][y] ? fast : slow; if (cost + c < costs[x + 1][y]) { costs[x + 1][y] = cost + c; todo.push({-(cost + c), x + 1, y}); } } if (y > 0) { int c = h[x][y - 1] ? fast : slow; if (cost + c < costs[x][y - 1]) { costs[x][y - 1] = cost + c; todo.push({-(cost + c), x, y - 1}); } } if (y < g - 1) { int c = h[x][y] ? fast : slow; if (cost + c < costs[x][y + 1]) { costs[x][y + 1] = cost + c; todo.push({-(cost + c), x, y + 1}); } } } return costs; } vector<vector<vector<vector<int>>>> all_costs() { vector<vector<vector<vector<int>>>> costs(g, vector<vector<vector<int>>>(g)); for (int x = 0; x < g; ++x) { for (int y = 0; y < g; ++y) { costs[x][y] = dijkstra(x, y); } } return costs; } long long calc_income() { vector<vector<vector<vector<int>>>> costs = all_costs(); long long s = 0; for (int i = 0; i < n; ++i) { auto [a, b] = ab[i]; auto [c, d] = cd[i]; int cost = costs[a][b][c][d]; int j = 0; while ((cost - slow * j) % fast) { ++j; } s += (cost - slow * j) / fast; } return 60 * s; } tuple<int,int,int,int> choose_road(int turn) { vector<tuple<bool,int,int>> sampled; while (sampled.size() < 4 && timer.stopwatch() < time_limit) { if (engine() % 2) { int x = engine() % g; int y = engine() % (g - 1); if (x % 3 != 2) { continue; } if (!h[x][y]) { sampled.push_back({true, x, y}); } } else { int x = engine() % (g - 1); int y = engine() % g; if (y % 3 != 2) { continue; } if (!v[x][y]) { sampled.push_back({false, x, y}); } } } int max_profit = 0; int best = -1; for (int i = 0; i < (int)sampled.size(); ++i) { auto [is_h, x, y] = sampled[i]; if (is_h) { h[x][y] = true; } else { v[x][y] = true; } long long new_income = calc_income(); long long profit = (new_income - income) * (t - turn - 1); if (max_profit < profit) { max_profit = profit; best = i; } if (is_h) { h[x][y] = false; } else { v[x][y] = false; } } if (best == -1) { if (timer.stopwatch() < time_limit) { return choose_road(turn); } else { return {-1, -1, -1, -1}; } } auto [is_h, x, y] = sampled[best]; if (is_h) { h[x][y] = true; return {x, y, x, y + 1}; } else { v[x][y] = true; return {x, y, x + 1, y}; } } }; int main() { Input input; input.input(); Solver solver(input); solver.solve(); cerr << solver.money << endl; cerr << solver.timer.stopwatch() << endl; return 0; }