結果
| 問題 | No.5023 Airlines Optimization |
| コンテスト | |
| ユーザー |
ebicochineal
|
| 提出日時 | 2026-02-28 16:09:49 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 805 ms / 1,000 ms |
| コード長 | 3,521 bytes |
| 記録 | |
| コンパイル時間 | 1,725 ms |
| コンパイル使用メモリ | 130,368 KB |
| 実行使用メモリ | 7,848 KB |
| スコア | 12,734,582 |
| 最終ジャッジ日時 | 2026-02-28 16:11:17 |
| 合計ジャッジ時間 | 87,329 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 100 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <random>
#include <chrono>
#include <cstdio>
using namespace std;
const int TIME_MIN = 6 * 60;
const int TIME_MAX = 21 * 60;
struct City { int id; long long x, y, w; };
struct Flight { int from, to, s, t; };
int calc_dur(const City& a, const City& b) {
double d = sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
return (int)ceil((60.0 * d / 800.0 + 40.0) / 5.0) * 5;
}
class Solver {
int N, M, K;
double R;
vector<City> cities;
vector<vector<Flight>> schedule;
public:
void solve() {
if (!(cin >> N >> R)) return;
cities.resize(N);
for (int i = 0; i < N; ++i) cin >> cities[i].x >> cities[i].y >> cities[i].w;
cin >> M;
for (int i = 0; i < M; ++i) {
int a, b, sh, sm, th, tm; char c;
cin >> a >> sh >> c >> sm >> b >> th >> c >> tm;
}
cin >> K;
vector<pair<long long, int>> pop_rank;
for(int i=0; i<N; ++i) pop_rank.push_back({cities[i].w, i + 1});
sort(pop_rank.rbegin(), pop_rank.rend());
// 上位3都市をスーパーハブにする
vector<int> hubs;
for(int i=0; i<3; ++i) hubs.push_back(pop_rank[i].second);
schedule.resize(K);
mt19937 engine(42);
for (int k = 0; k < K; ++k) {
int cur_t = TIME_MIN;
int u, v;
if (k < 6) {
// ハブ間シャトル (機体 0-5)
u = hubs[k % 3];
v = hubs[(k + 1) % 3];
} else {
// ハブと地方の往復 (機体 6-24)
u = hubs[engine() % hubs.size()];
v = (engine() % N) + 1;
while(v == u) v = (v % N) + 1;
}
int cur_loc = u;
while (true) {
int dest = (cur_loc == u) ? v : u;
int d = calc_dur(cities[cur_loc - 1], cities[dest - 1]);
if (cur_t + d > TIME_MAX) break;
schedule[k].push_back({cur_loc, dest, cur_t, cur_t + d});
cur_t += d;
cur_loc = dest;
}
}
auto start_time = chrono::system_clock::now();
while (true) {
auto now = chrono::system_clock::now();
if (chrono::duration_cast<chrono::milliseconds>(now - start_time).count() > 800) break;
int k = engine() % K;
if (schedule[k].size() < 2) continue;
int f_idx = engine() % schedule[k].size();
int diff = (engine() % 2 == 0 ? 5 : -5);
int new_s = schedule[k][f_idx].s + diff;
int new_t = schedule[k][f_idx].t + diff;
if (new_s >= TIME_MIN && new_t <= TIME_MAX) {
bool ok = true;
if (f_idx > 0 && schedule[k][f_idx-1].t > new_s) ok = false;
if (f_idx < (int)schedule[k].size()-1 && new_t > schedule[k][f_idx+1].s) ok = false;
if (ok) {
schedule[k][f_idx].s = new_s;
schedule[k][f_idx].t = new_t;
}
}
}
for (int k = 0; k < K; ++k) {
printf("%d\n", (int)schedule[k].size());
for (auto& f : schedule[k]) {
printf("%d %02d:%02d %d %02d:%02d\n", f.from, f.s/60, f.s%60, f.to, f.t/60, f.t%60);
}
}
}
};
int main() {
Solver s;
s.solve();
return 0;
}
ebicochineal