結果
| 問題 | No.5023 Airlines Optimization |
| コンテスト | |
| ユーザー |
ebicochineal
|
| 提出日時 | 2026-02-28 17:19:18 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 1,000 ms |
| コード長 | 5,699 bytes |
| 記録 | |
| コンパイル時間 | 2,139 ms |
| コンパイル使用メモリ | 137,828 KB |
| 実行使用メモリ | 7,844 KB |
| スコア | 35,623,340 |
| 最終ジャッジ日時 | 2026-02-28 17:19:27 |
| 合計ジャッジ時間 | 8,354 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
const int TARGET_START = 11 * 60;
const int TARGET_END = 21 * 60;
const int TARGET_STEP = 30;
struct City { int id; long long x, y, w; };
struct Flight { int from, to, s, t; };
inline 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<int> get_latest_departure_all(const vector<Flight>& all_flights, int dst, int target) {
vector<int> best(N, -1e9);
best[dst] = target;
for (int i = (int)all_flights.size() - 1; i >= 0; --i) {
const auto& f = all_flights[i];
if (f.t <= best[f.to] && f.s > best[f.from]) {
best[f.from] = f.s;
}
}
return best;
}
long long evaluate_config(vector<Flight>& flights) {
sort(flights.begin(), flights.end(), [](const Flight& a, const Flight& b){
return a.s < b.s;
});
long long total_v = 0;
for (int dst = 0; dst < N; ++dst) {
for (int target = TARGET_START; target <= TARGET_END; target += TARGET_STEP) {
vector<int> ci_dep = get_latest_departure_all(flights, dst, target);
for (int src = 0; src < N; ++src) {
if (src == dst) continue;
double dx = cities[src].x - cities[dst].x, dy = cities[src].y - cities[dst].y;
if (sqrt(dx*dx + dy*dy) < 0.25 * R) continue;
if (ci_dep[src] > TIME_MIN) total_v += cities[src].w * cities[dst].w;
}
}
}
return total_v;
}
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());
long long best_total_score = -1;
vector<vector<Flight>> best_schedule(K);
auto start_time = chrono::system_clock::now();
for (int i = 0; i < min(N, 5); ++i) {
int h = pop_rank[i].second;
vector<int> spokes;
for(auto& p : pop_rank) {
if(p.second == h) continue;
double dx = cities[h-1].x - cities[p.second-1].x, dy = cities[h-1].y - cities[p.second-1].y;
if(sqrt(dx*dx + dy*dy) >= 0.25 * R) spokes.push_back(p.second);
}
if (spokes.empty()) continue;
vector<vector<Flight>> current_sched(K);
vector<Flight> all_f;
for (int k = 0; k < K; ++k) {
int v = spokes[k % spokes.size()];
int cur_t = TIME_MIN, cur_loc = h, d = calc_dur(cities[h-1], cities[v-1]);
while (cur_t + d <= TIME_MAX) {
int dest = (cur_loc == h) ? v : h;
current_sched[k].push_back({cur_loc - 1, dest - 1, cur_t, cur_t + d});
all_f.push_back({cur_loc - 1, dest - 1, cur_t, cur_t + d});
cur_t += d; cur_loc = dest;
}
}
long long sc = evaluate_config(all_f);
if (sc > best_total_score) { best_total_score = sc; best_schedule = current_sched; }
}
for (int i = 0; i < min(N, 3); ++i) {
for (int j = i + 1; j < min(N, 3); ++j) {
int h1 = pop_rank[i].second, h2 = pop_rank[j].second;
double dxh = cities[h1-1].x - cities[h2-1].x, dyh = cities[h1-1].y - cities[h2-1].y;
if(sqrt(dxh*dxh + dyh*dyh) < 0.25 * R) continue;
vector<vector<Flight>> current_sched(K);
vector<Flight> all_f;
for (int k = 0; k < K; ++k) {
int u, v;
if (k < 4) { u = h1; v = h2; }
else {
u = (k % 2 == 0) ? h1 : h2;
v = pop_rank[(k / 2) % N + 1].second; // 簡易割り当て
if (v == h1 || v == h2) v = pop_rank[0].second == u ? pop_rank[1].second : pop_rank[0].second;
}
int cur_t = TIME_MIN, cur_loc = u, d = calc_dur(cities[u-1], cities[v-1]);
while (cur_t + d <= TIME_MAX) {
int dest = (cur_loc == u) ? v : u;
current_sched[k].push_back({cur_loc - 1, dest - 1, cur_t, cur_t + d});
all_f.push_back({cur_loc - 1, dest - 1, cur_t, cur_t + d});
cur_t += d; cur_loc = dest;
}
}
long long sc = evaluate_config(all_f);
if (sc > best_total_score) { best_total_score = sc; best_schedule = current_sched; }
}
}
for (int k = 0; k < K; ++k) {
printf("%d\n", (int)best_schedule[k].size());
for (auto& f : best_schedule[k]) {
printf("%d %02d:%02d %d %02d:%02d\n", f.from + 1, f.s/60, f.s%60, f.to + 1, f.t/60, f.t%60);
}
}
}
};
int main() { Solver().solve(); return 0; }
ebicochineal