QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#175516#7184. Transport Plusesjsannemo#ML 279ms450504kbC++172.5kb2023-09-10 18:58:492023-09-10 18:58:49

Judging History

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

  • [2023-09-10 18:58:49]
  • 评测
  • 测评结果:ML
  • 用时:279ms
  • 内存:450504kb
  • [2023-09-10 18:58:49]
  • 提交

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(yh);
	ys.insert(ye);

#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;
	}
}

詳細信息

Test #1:

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

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

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

input:

0 0
1 1
1 1

output:

0.0000000000
0

result:

ok correct

Test #4:

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

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

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

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

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

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

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

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

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

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: 0ms
memory: 3776kb

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: 1ms
memory: 3968kb

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: 0
Accepted
time: 1ms
memory: 3836kb

input:

1 12
100 0
10 89
0 100

output:

122.0000000000
3
0 100 100
1 0 89
0 10 89

result:

ok correct

Test #16:

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

input:

2 1
2 1
5 1
1 3
6 3

output:

3.0000000000
1
0 5 1

result:

ok correct

Test #17:

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

input:

2 2
2 1
5 1
1 3
6 3

output:

3.0000000000
1
0 5 1

result:

ok correct

Test #18:

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

input:

1 2
1 1
5 3
7 2

output:

4.0000000000
3
0 1 2
1 5 2
0 5 3

result:

ok correct

Test #19:

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

input:

1 2
1 1
5 4
6 2

output:

4.0000000000
3
0 1 2
1 6 4
0 5 4

result:

ok correct

Test #20:

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

input:

12 1
77 80
76 78
77 81
76 79
77 78
75 80
75 79
76 80
78 81
77 81
76 81
76 80
77 79
76 79

output:

1.0000000000
1
3 76 78

result:

ok correct

Test #21:

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

input:

5 1
40 69
37 71
37 69
36 71
38 70
40 72
40 71

output:

1.0000000000
1
1 37 71

result:

ok correct

Test #22:

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

input:

8 1
84 27
86 32
85 31
83 27
86 27
85 28
83 27
83 32
85 31
87 29

output:

1.0000000000
1
3 86 32

result:

ok correct

Test #23:

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

input:

11 1
95 30
99 36
96 33
95 36
94 30
98 33
98 36
97 31
99 33
99 31
98 35
95 36
100 32

output:

1.0000000000
1
2 99 36

result:

ok correct

Test #24:

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

input:

4 1
19 37
18 32
18 36
21 36
19 33
22 34

output:

2.0000000000
2
3 18 33
0 18 32

result:

ok correct

Test #25:

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

input:

7 1
49 6
48 8
46 3
49 9
45 6
43 3
49 8
43 8
48 2

output:

1.0000000000
1
5 48 8

result:

ok correct

Test #26:

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

input:

10 0
75 31
74 34
77 36
79 34
74 37
75 32
76 31
81 37
79 34
77 28
80 36
80 28

output:

0.0000000000
4
4 74 32
3 77 37
1 77 34
2 74 34

result:

ok correct

Test #27:

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

input:

3 3
74 19
75 15
70 17
74 10
75 17

output:

4.0000000000
2
2 74 15
0 75 15

result:

ok correct

Test #28:

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

input:

6 1
38 6
35 3
32 13
34 4
37 4
28 10
37 12
35 14

output:

3.0000000000
3
0 37 6
3 35 4
0 35 3

result:

ok correct

Test #29:

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

input:

9 2
91 54
90 52
86 61
90 59
90 63
97 54
93 60
96 56
85 63
89 58
95 59

output:

2.2360679775
1
0 90 52

result:

ok correct

Test #30:

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

input:

3 1
28 85
24 87
23 94
29 87
23 86

output:

2.0000000000
2
0 29 85
2 24 87

result:

ok correct

Test #31:

score: 0
Accepted
time: 4ms
memory: 6836kb

input:

18 1
56 70
54 77
56 72
52 71
54 69
53 67
52 72
55 73
51 71
59 74
49 77
58 80
59 72
60 77
50 70
56 71
61 71
63 79
60 76
54 69

output:

2.0000000000
2
0 56 69
3 54 77

result:

ok correct

Test #32:

score: 0
Accepted
time: 17ms
memory: 30508kb

input:

28 1
70 72
62 63
78 73
80 64
74 74
55 60
77 55
58 61
64 57
68 65
75 73
64 75
76 60
77 58
60 65
64 67
79 66
58 78
64 58
66 55
62 62
55 57
65 55
73 76
58 70
76 56
66 68
77 76
64 55
55 65

output:

3.0000000000
3
0 70 73
9 75 62
19 62 63

result:

ok correct

Test #33:

score: 0
Accepted
time: 45ms
memory: 68824kb

input:

40 1
72 56
63 68
70 58
70 63
55 55
52 76
83 52
84 86
49 66
63 76
57 65
82 77
50 78
82 76
78 53
74 58
66 65
80 71
57 77
54 71
77 86
67 88
71 71
80 74
65 70
48 66
80 86
82 69
72 78
72 73
74 65
84 49
68 75
47 52
75 82
83 55
52 76
49 88
47 48
70 61
45 60
44 49

output:

2.0000000000
2
27 63 78
8 63 68

result:

ok correct

Test #34:

score: 0
Accepted
time: 97ms
memory: 182628kb

input:

50 1
67 73
81 81
88 73
64 40
45 53
70 65
50 73
70 50
81 53
75 56
43 76
74 40
82 59
41 66
41 45
45 48
84 46
78 50
88 69
70 45
80 82
69 43
55 42
52 74
59 85
57 70
43 53
53 45
66 46
43 81
64 55
78 61
66 51
48 40
44 73
87 42
68 73
77 60
77 45
87 65
58 56
47 58
44 54
57 77
62 85
80 83
82 54
54 82
69 48
4...

output:

2.0000000000
2
5 50 53
7 81 81

result:

ok correct

Test #35:

score: 0
Accepted
time: 279ms
memory: 450504kb

input:

59 1
15 7
43 24
67 8
23 32
62 55
65 33
33 17
47 22
59 30
56 40
51 46
19 23
63 16
68 30
60 34
59 19
51 42
69 12
68 57
50 59
16 20
46 42
33 11
56 41
41 14
50 56
61 44
67 14
47 57
69 59
34 55
66 47
42 44
39 34
14 32
16 53
29 9
52 55
37 41
49 38
18 27
50 43
41 43
30 32
20 61
42 45
57 39
20 17
70 8
36 27...

output:

2.0000000000
2
50 49 43
52 43 24

result:

ok correct

Test #36:

score: -100
Memory Limit Exceeded

input:

65 2
60 33
67 26
70 39
46 50
24 42
73 36
33 68
51 16
63 79
40 77
65 30
48 58
44 38
31 14
40 69
84 30
47 38
82 39
48 35
87 37
68 58
82 41
88 38
38 62
43 48
51 19
69 63
87 64
66 49
72 48
63 19
67 79
42 41
49 56
59 19
57 65
41 64
55 52
60 53
75 61
59 21
76 36
35 21
61 77
37 75
55 13
87 60
61 45
93 70
7...

output:


result: