QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#173559 | #7184. Transport Pluses | ucup-team197# | RE | 1ms | 3804kb | C++20 | 3.0kb | 2023-09-10 00:03:04 | 2023-09-10 00:03:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> void check_min(T &a, const T &b){ a = (a < b) ? a : b; }
template<class T> void check_max(T &a, const T &b){ a = (a > b) ? a : b; }
#define all(x) (x).begin(), (x).end()
struct Path{
vector<pair<int, int>> v;
vector<int> plus_used;
double dist;
friend bool operator<(const Path &l, const Path &r){
return l.dist < r.dist;
}
};
double sq(double x){
return x * x;
}
double dist(pair<int, int> p1, pair<int, int> p2){
return sqrt(sq(p1.first - p2.first) + sq(p1.second - p2.second));
}
pair<int, int> closest_point(pair<int, int> p, pair<int, int> plus){
if(abs(plus.first - p.first) < abs(plus.second - p.second)){
return {plus.first, p.second};
}
return {p.first, plus.second};
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, t;
cin >> n >> t;
pair<int, int> h;
cin >> h.first >> h.second;
pair<int, int> e;
cin >> e.first >> e.second;
vector<pair<int, int>> p(n);
for(int i = 0; i < n; ++i)
cin >> p[i].first >> p[i].second;
Path best_path;
best_path.v = {h, e};
best_path.dist = sqrt(sq(h.first - e.first) + sq(h.second - e.second));
best_path.plus_used.push_back(0);
for(int i = 0; i < n; ++i){
Path cand;
cand.v = {h};
cand.v.push_back(closest_point(h, p[i]));
cand.dist = dist(closest_point(h, p[i]), h);
cand.v.push_back(closest_point(e, p[i]));
cand.v.push_back(e);
cand.dist += dist(closest_point(e, p[i]), e);
cand.dist += t;
cand.plus_used = {0, i + 1, 0};
if(cand < best_path)
best_path = cand;
}
int h_plus = 0, e_plus = 0;
double dh, de;
dh = dist(closest_point(h, p[0]), h);
de = dist(closest_point(e, p[0]), e);
for(int i = 1; i < n; ++i){
auto cand_dist = dist(closest_point(h, p[i]), h);
if(cand_dist < dh){
dh = cand_dist;
h_plus = i;
}
cand_dist = dist(e, closest_point(e, p[i]));
if(cand_dist < de){
de = cand_dist;
e_plus = i;
}
}
Path cand;
cand.v.push_back(h);
cand.v.push_back(closest_point(h, p[h_plus]));
cand.dist = dist(h, closest_point(h, p[h_plus]));
cand.dist += t;
cand.v.push_back({p[h_plus].first, p[e_plus].second});
cand.dist += t;
cand.v.push_back(closest_point(e, p[e_plus]));
cand.v.push_back(e);
cand.dist += dist(e, closest_point(e, p[e_plus]));
cand.plus_used = {0, h_plus + 1, e_plus + 1, 0};
if(cand < best_path)
best_path = cand;
cout << fixed << setprecision(10) << best_path.dist << "\n";
cout << (int)best_path.v.size() - 1 << "\n";
for(int i = 1; i < best_path.v.size(); ++i){
auto [x, y] = best_path.v[i];
int mode = best_path.plus_used[i - 1];
cout << mode << " " << x << " " << y << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3728kb
input:
1 2 1 1 5 3 6 2
output:
4.0000000000 3 0 1 2 1 5 2 0 5 3
result:
ok correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 3804kb
input:
2 1 1 1 6 1 1 3 6 3
output:
2.0000000000 4 0 1 1 1 1 3 2 6 1 0 6 1
result:
ok correct
Test #3:
score: -100
Runtime Error
input:
0 0 1 1 1 1