結果
| 問題 |
No.5016 Worst Mayor
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-29 15:35:07 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 434 ms / 2,000 ms |
| コード長 | 6,327 bytes |
| コンパイル時間 | 3,857 ms |
| コンパイル使用メモリ | 251,428 KB |
| 実行使用メモリ | 24,288 KB |
| スコア | 16,772,465,536 |
| 平均クエリ数 | 400.00 |
| 最終ジャッジ日時 | 2023-04-29 15:35:36 |
| 合計ジャッジ時間 | 27,667 ms |
|
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
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 = 350;
constexpr int min_people = 25;
constexpr int max_people = 100;
constexpr int add_people = 20;
struct Solver {
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;
Solver(const Input& input) {
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) {
cin >> money >> people;
//money += income;
if (turn >= no_construction_turn) {
cout << 3 << endl;
money += bonus;
} else if (money >= expense(people)) {
auto [x, y, z, w] = choose_road();
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() {
for (int y = 4; y < 9; ++y) {
if (!h[7][y]) {
h[7][y] = true;
return {7, y, 7, y + 1};
}
}
for (int x = 4; x < 9; ++x) {
if (!v[x][7]) {
v[x][7] = true;
return {x, 7, x + 1, 7};
}
}
for (int y = 4; y < 9; ++y) {
if (!h[4][y]) {
h[4][y] = true;
return {4, y, 4, y + 1};
}
}
for (int x = 4; x < 9; ++x) {
if (!v[x][4]) {
v[x][4] = true;
return {x, 4, x + 1, 4};
}
}
for (int y = 4; y < 9; ++y) {
if (!h[10][y]) {
h[10][y] = true;
return {10, y, 10, y + 1};
}
}
for (int x = 4; x < 9; ++x) {
if (!v[x][10]) {
v[x][10] = true;
return {x, 10, x + 1, 10};
}
}
for (int x = 4; x <= 10; x += 3) {
for (int y = 0; y < g - 1; ++y) {
if (!h[x][y]) {
h[x][y] = true;
return {x, y, x, y + 1};
}
}
}
for (int y = 4; y <= 10; y += 3) {
for (int x = 0; x < g - 1; ++x) {
if (!v[x][y]) {
v[x][y] = true;
return {x, y, x + 1, y};
}
}
}
return {-1, -1, -1, -1};
}
};
int main() {
Input input;
input.input();
Solver solver(input);
solver.solve();
cerr << solver.money << endl;
return 0;
}