QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#175513#7184. Transport Plusesjsannemo#WA 1ms3832kbC++172.5kb2023-09-10 18:57:112023-09-10 18:57:11

Judging History

你现在查看的是最新测评结果

  • [2023-09-10 18:57:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3832kb
  • [2023-09-10 18:57:11]
  • 提交

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));

	vector<tuple<int, int, int>> M;
	rep(i,1,sz(pts)) {
		int p = pts[i];
		if (p >= SOURCE) {
			if (xh == xc[p - SOURCE] && yh == yc[p - SOURCE]) continue;
			int w = 0;
			if (pts[i - 1] < SOURCE) w = pts[i-1] + 1;
			M.emplace_back(w, xc[p - SOURCE], yc[p - SOURCE]);
			xh = xc[p - SOURCE];
			yh = yc[p - SOURCE];
		}
	}
	cout << M.size() << endl;
	for (auto [a, b, c] : M) {
		cout << a << " " << b << " " << c << endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3812kb

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: 3768kb

input:

2 1
1 1
6 1
1 3
6 3

output:

2.0000000000
2
1 1 3
2 6 1

result:

ok correct

Test #3:

score: 0
Accepted
time: 1ms
memory: 3692kb

input:

0 0
1 1
1 1

output:

0.0000000000
0

result:

ok correct

Test #4:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

0 0
100 100
0 0

output:

141.4213562373
1
0 0 0

result:

ok correct

Test #5:

score: 0
Accepted
time: 1ms
memory: 3832kb

input:

1 0
100 100
0 0
100 100

output:

100.0000000000
2
1 0 100
0 0 0

result:

ok correct

Test #6:

score: 0
Accepted
time: 1ms
memory: 3812kb

input:

1 0
100 100
0 0
100 0

output:

0.0000000000
1
1 0 0

result:

ok correct

Test #7:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

1 0
100 100
0 0
0 100

output:

0.0000000000
1
1 0 0

result:

ok correct

Test #8:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

1 100
50 50
0 0
50 50

output:

70.7106781187
1
0 0 0

result:

ok correct

Test #9:

score: 0
Accepted
time: 1ms
memory: 3732kb

input:

1 100
50 50
0 0
0 50

output:

70.7106781187
1
0 0 0

result:

ok correct

Test #10:

score: 0
Accepted
time: 1ms
memory: 3676kb

input:

1 100
50 50
0 0
51 51

output:

70.7106781187
1
0 0 0

result:

ok correct

Test #11:

score: 0
Accepted
time: 1ms
memory: 3692kb

input:

1 100
50 50
0 0
2 53

output:

70.7106781187
1
0 0 0

result:

ok correct

Test #12:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

1 100
0 0
100 100
50 50

output:

141.4213562373
1
0 100 100

result:

ok correct

Test #13:

score: 0
Accepted
time: 1ms
memory: 3740kb

input:

1 33
0 0
100 100
50 50

output:

133.0000000000
3
0 0 50
1 100 50
0 100 100

result:

ok correct

Test #14:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

1 12
100 0
11 90
0 100

output:

122.0000000000
3
0 100 100
1 11 100
0 11 90

result:

ok correct

Test #15:

score: -100
Wrong Answer
time: 1ms
memory: 3760kb

input:

1 12
100 0
10 89
0 100

output:

123.0000000000
3
0 100 100
1 10 100
0 10 89

result:

wrong answer read 123.000000 but expected 122.000000, error = 1.000000