QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#170882#7184. Transport Plusesucup-team1303#ML 4ms4876kbC++143.1kb2023-09-09 16:09:212023-09-09 16:09:25

Judging History

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

  • [2023-09-09 16:09:25]
  • 评测
  • 测评结果:ML
  • 用时:4ms
  • 内存:4876kb
  • [2023-09-09 16:09:21]
  • 提交

answer

#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 120;
const double eps = 1e-5;
int n, m, x[N], y[N], fr[N * N];//, kx[N], ky[N];
bool vis[N];
inline int id(int x, int y) {
	return x * 101 + y;
}
pair <int, int> iid(int x) {
	return make_pair(x / 101, x % 101);
}
vector <pair <int, double>> v[N * N];
double f[N * N];
inline double calc(int kx, int ky, int tx, int ty) {
	return sqrt((kx - tx) * (kx - tx) + (ky - ty) * (ky - ty));
}
priority_queue <pair <double, int>, vector <pair <double, int>>, greater <pair <double, int>>> q;
signed main() {
	// cout << id(0, 0) << endl;
	// cout << id(0, 100) << endl;
	// cout << id(1, 0) << endl;
	// return 0;
	cin >> n >> m;
	int sx, sy, px, py;
	cin >> sx >> sy >> px >> py;
	int s = id(sx, sy), p = id(px, py);
	int tot = id(100, 100), h = tot;
	// cout << N * N - tot << endl;
	F(i, 1, n) {
		read(x[i]), read(y[i]);
		tot++;
		F(j, 0, 100) {
			// cout << x[i] << " " << j << " " << j << " " << y[i] << endl;
			v[id(x[i], j)].emplace_back(tot, m);
			v[id(j, y[i])].emplace_back(tot, m);
			
			v[tot].emplace_back(id(x[i], j), 0);
			v[tot].emplace_back(id(j, y[i]), 0);
		}
	}
	F(i, 0, 100)
		F(j, 0, 100) {
			// f[id(i, j)] = 1e18;
			v[id(sx, sy)].emplace_back(id(i, j), calc(sx, sy, i, j));
			// if (i == 1 && j == 2) cout << "~ " << calc(sx, sy, i, j) << endl;
			v[id(i, j)].emplace_back(id(px, py), calc(px, py, i, j));
			// if (i == 5 && j == 2) cout << fixed << setprecision(10) << calc(px, py, i, j) << endl;
			// f[i] = calc(x[i], y[i], sx, sy);
		}
	F(i, 0, tot) f[i] = 1e18;
	f[s] = 0;
	q.push(make_pair(0, s));
	while (q.size()) {
		int x = q.top().second; q.pop();
		// cout << x << " " << f[x] << endl;
		for (auto [i, j]: v[x])
			if (f[x] + j + eps < f[i]) {
				// if (x == s && i == p) {
				// 	cout << "~~~ " << j << endl;
				// }
				f[i] = f[x] + j;
				fr[i] = x;
				q.push(make_pair(f[i], i));
			}
	}
	// cout << f[id(5, 2)] << endl;
	// cout << tot << " " << f[tot] << endl;
	// cout << fr[p] << endl;
	cout << fixed << setprecision(5) << f[p] << endl;
	vector <pair <int, pair <int, int>>> ans;
	while (p != s) {
		if (fr[p] >= h) {
			ans.emplace_back(fr[p] - h, iid(p));
			p = fr[fr[p]];
		} else {
			ans.emplace_back(0, iid(p));
			p = fr[p];
		}
	}
	cout << ans.size() << endl;
	DF(i, SZ(ans), 0) cout << ans[i].first << " " << ans[i].second.first << " " << ans[i].second.second << '\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 4856kb

input:

1 2
1 1
5 3
6 2

output:

4.00000
3
0 1 2
1 5 2
0 5 3

result:

ok correct

Test #2:

score: 0
Accepted
time: 3ms
memory: 4872kb

input:

2 1
1 1
6 1
1 3
6 3

output:

2.00000
2
1 0 3
2 6 1

result:

ok correct

Test #3:

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

input:

0 0
1 1
1 1

output:

0.00000
0

result:

ok correct

Test #4:

score: -100
Memory Limit Exceeded

input:

0 0
100 100
0 0

output:

141.42136

result: