QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#487101#5341. Shopping MallsPetroTarnavskyi#AC ✓7ms4176kbC++201.7kb2024-07-22 16:16:162024-07-22 16:16:16

Judging History

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

  • [2024-07-22 16:16:16]
  • 评测
  • 测评结果:AC
  • 用时:7ms
  • 内存:4176kb
  • [2024-07-22 16:16:16]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const db INF = 1e18;

template<typename T>
void updMin(T& a, T b)
{
	a = min(a, b);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	VI z(n), x(n), y(n);
	vector d(n, vector<db>(n, INF));
	vector mid(n, VI(n, -1));
	FOR(i, 0, n)
	{
		cin >> z[i] >> x[i] >> y[i];
	}
	FOR(i, 0, n)
		d[i][i] = 0;
	while (m--)
	{
		int u, v;
		string s;
		cin >> u >> v >> s;
		db dist = hypot(x[v] - x[u], y[v] - y[u], 5 * (z[v] - z[u]));
		if (s[0] == 'w' || s[0] == 's')
		{
			updMin(d[u][v], dist);
			updMin(d[v][u], dist);
		}
		else if (s[0] == 'l')
		{
			updMin(d[u][v], 1.0);
			updMin(d[v][u], 1.0);
		}
		else
		{
			assert(s[0] == 'e');
			updMin(d[u][v], 1.0);
			updMin(d[v][u], 3 * dist);
		}
	}
	FOR(k, 0, n)
	{
		FOR(i, 0, n)
		{
			FOR(j, 0, n)
			{
				db dikj = d[i][k] + d[k][j];
				if (dikj < d[i][j])
				{
					d[i][j] = dikj;
					mid[i][j] = k;
				}
			}
		}
	}
	function<void(int, int)> printPath = [&](int u, int v)
	{
		if (u == v)
			return;
		if (mid[u][v] == -1)
		{
			cout << u << " ";
			return;
		}
		printPath(u, mid[u][v]);
		printPath(mid[u][v], v);
	};
	int q;
	cin >> q;
	while (q--)
	{
		int u, v;
		cin >> u >> v;
		printPath(u, v);
		cout << v << "\n";
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3856kb

input:

6 7
3 2 3
3 5 3
2 2 3
2 6 4
1 1 3
1 4 2
0 1 walking
0 2 lift
1 2 stairs
2 3 walking
3 4 escalator
5 3 escalator
4 5 walking
5
0 1
1 2
3 5
5 3
5 1

output:

0 1
1 0 2
3 4 5
5 3
5 3 2 0 1

result:

ok 5 lines

Test #2:

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

input:

166 409
0 3 24
0 4 42
0 5 5
0 5 23
0 5 42
0 6 5
0 7 7
0 7 38
0 10 29
0 16 45
0 17 34
0 18 18
0 22 45
0 23 5
0 23 8
0 23 26
0 23 42
0 25 36
0 28 34
0 30 27
0 32 45
0 33 18
0 33 36
0 35 4
0 38 7
0 38 38
0 40 35
0 41 45
0 42 5
0 42 16
0 42 23
0 42 42
0 44 9
0 44 29
0 44 41
1 5 5
1 5 19
1 5 23
1 5 42
1 ...

output:

3 37 36 42 6 5
0 3 69 71 67
3 0 8
2 5 6
3 37 36 40
3 136 137 143 146
3 0 1 4
0 8 10 16 81 84 86 91 97
6 5 2 35 39 44 49 52 62 30
1 0 3 69
4 1 7 43 73 74 78 82 88 92
9 10
3 37 36 45 49 50 115
3 69 71 76
5 2 35 39 44 49 50 115 119
3 136 137 143 147 152 154 162
4 1 7 43 73 74 78 82 88 89 125 155
0 8 10...

result:

ok 1000 lines

Test #3:

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

input:

157 387
0 3 38
0 4 25
0 5 5
0 5 8
0 5 22
0 5 40
0 7 7
0 7 36
0 8 38
0 12 31
0 14 8
0 16 24
0 18 39
0 21 16
0 24 43
0 25 5
0 25 40
0 26 27
0 27 37
0 31 5
0 32 33
0 37 16
0 37 40
0 40 28
0 41 7
0 41 36
0 44 6
0 44 40
0 45 5
0 45 22
0 45 40
0 47 20
0 47 34
1 4 24
1 5 5
1 5 22
1 5 40
1 6 41
1 7 5
1 9 9
...

output:

1 8
5 0 7 40 71 105 102 107 111
5 0 7 40 71 105 102 104 101
8 7 40 71 105 130 132 136 141
5 0 7 40 41 44 49 57 61 29
2 3 1 4
1 8
4 98 104 108 109 112
7 40 71 64 66
5 0 7 40 41 44 49 57 61 150
1 3 10
4 1 9
1 4 35 33 42 47 51
3 1 4 127 131 135 140
8 9 12 18 22 27
1 9 11 13 19 26 28
0 7 40 71 105 130 1...

result:

ok 1000 lines

Test #4:

score: 0
Accepted
time: 2ms
memory: 3940kb

input:

175 445
0 5 5
0 5 18
0 5 21
0 5 34
0 5 38
0 6 5
0 7 7
0 7 34
0 13 34
0 15 18
0 20 16
0 20 26
0 21 5
0 21 38
0 23 34
0 24 5
0 26 21
0 30 37
0 33 21
0 34 7
0 34 34
0 38 5
0 38 21
0 38 38
0 39 9
0 39 26
0 39 38
1 5 5
1 5 16
1 5 21
1 5 38
1 7 4
1 7 27
1 7 37
1 9 9
1 9 36
1 15 24
1 18 28
1 20 4
1 21 5
1 ...

output:

8 1 2 58 55 57 56
4 3 7 35 63 61 66 68 13 14
0 5 9
7 35 63 92 122 124 127 129 128 98
4 3 7 35 63 61 66 68 13 14 16
1 2 148 151 155 157 160 162 164
5 0 27 31 38 39 98 102
2 148 151 150
6 5 1 2 58
1 2 148 151 150
7 35 63 61 59
3 1 2 89 86 88
4 3 8 10 15
0 27 31 38 46 51 110 111 115
2 148 151 155 156
1...

result:

ok 1000 lines

Test #5:

score: 0
Accepted
time: 7ms
memory: 4020kb

input:

198 515
0 4 7
0 5 5
0 5 24
0 5 44
0 6 18
0 6 30
0 6 43
0 7 7
0 7 40
0 13 23
0 15 38
0 18 19
0 20 4
0 20 38
0 24 5
0 24 44
0 25 45
0 27 20
0 30 36
0 30 45
0 32 7
0 36 28
0 38 45
0 39 41
0 40 7
0 40 9
0 40 40
0 43 31
0 44 5
0 44 24
0 44 44
0 46 8
0 47 26
0 47 42
0 47 45
1 1 29
1 3 48
1 4 4
1 5 5
1 5 2...

output:

2 73 79 80 84
2 133 138 144 153
6 8 44 76 78 80 84
0 1 38 37 47 50 146 143
5 2 170 166 171
2 39 46 49 55 59 61 90 119
5 9 10 13
4 5 6 3 40 45 36
7 0 4 5 6 8 44 76 107 137
7 0 4 5 2 103 99
5 9 11 17 21 27 32
5 2 133 138 144 154 157 121
3 6 5 2 133 130 139
2 133 138 144 148 15 16 19
4 11 17 21 27 29 1...

result:

ok 1000 lines

Test #6:

score: 0
Accepted
time: 6ms
memory: 3940kb

input:

195 516
0 1 34
0 5 5
0 5 13
0 5 25
0 5 45
0 7 3
0 7 7
0 7 34
0 7 41
0 13 49
0 14 40
0 17 12
0 17 24
0 20 7
0 22 5
0 22 45
0 23 49
0 25 40
0 28 32
0 30 21
0 33 9
0 35 7
0 35 41
0 36 45
0 36 49
0 37 26
0 39 5
0 39 25
0 39 37
0 39 45
0 41 4
0 42 19
0 42 48
1 2 14
1 3 45
1 5 5
1 5 25
1 5 45
1 6 29
1 7 3...

output:

2 7 3 70 73
6 5 13 14 82
5 11 12 18 22 60 91 121
2 11 19 25 27 63 61
4 7 3 70 73 68 69
1 35 33 36 70
4 7 12 19 20
5 11 12 18 22 60 91
0 7 12 19 20 21 59 90 119 151 185
6 2 7 8 42 75 106 135 169 174 179
4 7 12 19 20 21 59 90 119 151 185 187 188
6 5 13 14 111 109 116
6 5 13 20 21 59 90 119 126 122
5 1...

result:

ok 1000 lines