QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#175510 | #7184. Transport Pluses | jsannemo# | WA | 1ms | 3996kb | C++17 | 2.3kb | 2023-09-10 18:55:40 | 2023-09-10 18:55:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,f,t) for (int i = f; i < t; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define trav(a,x) for (auto& a : x)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
const double inf = 1.0/0;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, T;
cin >> N >> T;
int xh, yh, xe, ye;
cin >> xh >> yh >> xe >> ye;
vi X(N), Y(N);
rep(i,0,N) cin >> X[i] >> Y[i];
set<int> xs, ys;
xs.insert(all(X));
ys.insert(all(Y));
xs.insert(xh);
xs.insert(xe);
ys.insert(xh);
ys.insert(xe);
#define PLUS(k) (k)
#define SOURCE (PLUS(N) + 0)
#define SINK (PLUS(N) + 1)
#define PNT(k) ((SINK) + 1 + (k))
vector<vector<pair<int, double>>> G(2 + N);
vector<int> xc, yc;
xc.push_back(xh);
yc.push_back(yh);
xc.push_back(xe);
yc.push_back(ye);
rep(i,0,N) {
trav(x, xs) {
G[PLUS(i)].emplace_back(G.size(), 0);
G.push_back({});
G.back().emplace_back(PLUS(i), T);
xc.push_back(x);
yc.push_back(Y[i]);
}
trav(y, ys) {
G[PLUS(i)].emplace_back(G.size(), 0);
G.push_back({});
G.back().emplace_back(PLUS(i), T);
xc.push_back(X[i]);
yc.push_back(y);
}
}
rep(i,SOURCE,(int)G.size()) {
rep(j,SOURCE,i) {
int dx = xc[i - SOURCE] - xc[j - SOURCE];
int dy = yc[i - SOURCE] - yc[j - SOURCE];
double dist = sqrt(dx * dx + dy * dy);
G[i].emplace_back(j, dist);
G[j].emplace_back(i, dist);
}
}
vector<double> best(sz(G), inf);
vector<int> last(sz(G), -1);
set<pair<double, int>> Q;
best[SOURCE] = 0;
Q.emplace(0, SOURCE);
while (!Q.empty()) {
auto [dist, at] = *Q.begin(); Q.erase(Q.begin());
for (auto [to, cost] : G[at]) {
double ndist = dist + cost;
if (ndist < best[to]) {
if (best[to] != inf) {
Q.erase(Q.find(make_pair(best[to], to)));
}
best[to] = ndist;
last[to] = at;
Q.emplace(best[to], to);
}
}
}
cout << setprecision(10) << fixed << best[SINK] << endl;
int at = SINK;
vector<int> pts;
while (at != -1) {
pts.push_back(at);
at = last[at];
}
reverse(all(pts));
rep(i,1,sz(pts)) {
int p = pts[i];
if (p >= SOURCE) {
if (xh == xc[p - SOURCE] && yh == yc[p - SOURCE]) continue;
if (pts[i - 1] < SOURCE) cout << pts[i-1] + 1 << " ";
else cout << 0 << " ";
cout << xc[p - SOURCE] << " " << yc[p - SOURCE] << endl;
xh = xc[p - SOURCE];
yh = yc[p - SOURCE];
}
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3996kb
input:
1 2 1 1 5 3 6 2
output:
4.0000000000 0 1 2 1 5 2 0 5 3
result:
wrong answer arrived at (1.000000, 1.000000) instead of (5.000000, 3.000000)