QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#167676 | #7184. Transport Pluses | ucup-team1234# | WA | 2ms | 8128kb | C++14 | 5.7kb | 2023-09-07 16:34:17 | 2023-09-07 16:34:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, int> PDI;
typedef unsigned long long ULL;
const int N = 1e2 + 10;
const int mod = 998244353;
const double eps = 1e-5;
double f[N][N][N];
PDI mnx[N][N], mny[N][N];
int X[N], Y[N];
int sx, sy, tx, ty;
double dist(double x0, double y0, double x1, double y11)
{
return sqrt((x0 - x1) * (x0 - x1) + (y0 - y11) * (y0 - y11));
}
struct Operation
{
double x, y;
int id;
Operation() {}
Operation(double _x, double _y, int _id) : x(_x), y(_y), id(_id) {}
};
vector<Operation> ans;
map<PII, Operation> path;
int cmp(double x, double y)
{
if (fabs(x - y) < eps)
return 0;
if (x < y)
return -1;
return 1;
}
void dfs(int curx, int cury, int num)
{
if (curx == sx && cury == sy)
return;
if (num == 0) // 不用plus
{
ans.push_back(Operation(curx, cury, 0));
return; // 从起点走到(curx, cury), 结束
}
else if (cmp(f[num][curx][cury], f[num - 1][curx][cury]) >= 0) // 不用plus num
{
dfs(curx, cury, num - 1);
}
else // 用plus num
{
if (cmp(fabs(curx - X[num]), fabs(cury - Y[num])) == -1)
{
// (X[num], cury) -> (curx, cury)
if (fabs(curx - X[num]) > eps)
ans.push_back(Operation(curx, cury, 0));
// (X[num], cury)
if (mnx[num - 1][X[num]].first < mny[num - 1][Y[num]].first - eps)
{
// (X[num], second)
if (fabs(cury - mnx[num - 1][X[num]].second) >= eps)
{
ans.push_back(Operation(X[num], cury, num));
}
dfs(X[num], mnx[num - 1][X[num]].second, num - 1);
}
else
{
// (second, Y[num])
if (fabs(mny[num - 1][Y[num]].second - X[num]) < eps && fabs(cury - Y[num]) < eps)
{
dfs(mny[num - 1][Y[num]].second, Y[num], num - 1);
}
else
{
ans.push_back(Operation(X[num], cury, num));
dfs(mny[num - 1][Y[num]].second, Y[num], num - 1);
}
}
}
else // (curx, Y[num])
{
if (fabs(Y[num] - cury) >= eps)
{
ans.push_back(Operation(curx, cury, 0));
}
if (mnx[num - 1][X[num]].first < mny[num - 1][Y[num]].first - eps)
{
// (X[num], second)
if (fabs(curx - X[num]) >= eps || fabs(Y[num] - mnx[num - 1][X[num]].second) >= eps)
{
ans.push_back(Operation(curx, Y[num], num));
}
dfs(X[num], mnx[num - 1][X[num]].second, num - 1);
}
else
{
// (second, Y[num])
if (fabs(mny[num - 1][Y[num]].second - curx) < eps)
{
dfs(mny[num - 1][Y[num]].second, Y[num], num - 1);
}
else
{
ans.push_back(Operation(curx, Y[num], num));
dfs(mny[num - 1][Y[num]].second, Y[num], num - 1);
}
}
}
// t + min(mnx[i - 1][X[i]].first, mny[i - 1][Y[i]].first) + min(fabs(x - X[i]), fabs(y - Y[i]))
}
}
void solve()
{
int n, t;
cin >> n >> t;
cin >> sx >> sy >> tx >> ty;
for (int i = 1; i <= n; i++)
cin >> X[i] >> Y[i];
for (int i = 0; i <= 100; i++)
{
for (int j = 0; j <= 100; j++)
{
mnx[j][i] = mny[j][i] = make_pair(1e9, 110);
}
}
for (int i = 0; i <= 100; i++)
for (int j = 0; j <= 100; j++)
{
f[0][i][j] = dist(sx, sy, i, j);
// path[make_pair(i, j)] = Operation(sx, sy, 0);
// cout << i << ' ' << j << ' '<< f[0][i][j] << endl;
if (mnx[0][i].first >= f[0][i][j])
{
mnx[0][i].first = min(mnx[0][i].first, f[0][i][j]);
mnx[0][i].second = j;
}
if (mny[0][j].first >= f[0][i][j])
{
mny[0][j].first = min(mny[0][j].first, f[0][i][j]);
mny[0][j].second = i;
}
}
for (int i = 1; i <= n; i++)
{
for (int x = 0; x <= 100; x++)
{
for (int y = 0; y <= 100; y++)
{
f[i][x][y] = min(f[i - 1][x][y], t + min(mnx[i - 1][X[i]].first, mny[i - 1][Y[i]].first) + min(fabs(x - X[i]), fabs(y - Y[i])));
}
}
for (int x = 0; x <= 100; x++)
{
for (int y = 0; y <= 100; y++)
{
if (mnx[i][x].first >= f[i][x][y])
{
mnx[i][x].first = min(mnx[i][x].first, f[i][x][y]),
mnx[i][x].second = y;
}
if (mny[i][y].first >= f[i][x][y])
{
mny[i][y].first = min(mny[i][y].first, f[i][x][y]);
mny[i][y].second = x;
}
}
}
}
cout << fixed << setprecision(5) << f[n][tx][ty] << endl;
dfs(tx, ty, n);
cout << (int)ans.size() << '\n';
for (int i = (int)ans.size() - 1; i >= 0; i--)
{
cout << ans[i].id << ' ' << ans[i].x << ' ' << ans[i].y << endl;
}
}
/*
1 2
1 1
5 2
6 2
*/
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
T = 1;
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4420kb
input:
1 2 1 1 5 3 6 2
output:
4.00000 3 0 1.00000 2.00000 1 5.00000 2.00000 0 5.00000 3.00000
result:
ok correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 4488kb
input:
2 1 1 1 6 1 1 3 6 3
output:
2.00000 2 1 100.00000 3.00000 2 6.00000 1.00000
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 5928kb
input:
0 0 1 1 1 1
output:
0.00000 0
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 6248kb
input:
0 0 100 100 0 0
output:
141.42136 1 0 0.00000 0.00000
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 4320kb
input:
1 0 100 100 0 0 100 100
output:
100.00000 2 1 0.00000 100.00000 0 0.00000 0.00000
result:
ok correct
Test #6:
score: 0
Accepted
time: 1ms
memory: 4352kb
input:
1 0 100 100 0 0 100 0
output:
0.00000 1 1 0.00000 0.00000
result:
ok correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 6404kb
input:
1 0 100 100 0 0 0 100
output:
0.00000 1 1 0.00000 0.00000
result:
ok correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 4396kb
input:
1 100 50 50 0 0 50 50
output:
70.71068 1 0 0.00000 0.00000
result:
ok correct
Test #9:
score: 0
Accepted
time: 1ms
memory: 4200kb
input:
1 100 50 50 0 0 0 50
output:
70.71068 1 0 0.00000 0.00000
result:
ok correct
Test #10:
score: 0
Accepted
time: 1ms
memory: 4268kb
input:
1 100 50 50 0 0 51 51
output:
70.71068 1 0 0.00000 0.00000
result:
ok correct
Test #11:
score: 0
Accepted
time: 0ms
memory: 4388kb
input:
1 100 50 50 0 0 2 53
output:
70.71068 1 0 0.00000 0.00000
result:
ok correct
Test #12:
score: 0
Accepted
time: 1ms
memory: 6288kb
input:
1 100 0 0 100 100 50 50
output:
141.42136 1 0 100.00000 100.00000
result:
ok correct
Test #13:
score: 0
Accepted
time: 1ms
memory: 4348kb
input:
1 33 0 0 100 100 50 50
output:
133.00000 3 0 0.00000 50.00000 1 100.00000 50.00000 0 100.00000 100.00000
result:
ok correct
Test #14:
score: 0
Accepted
time: 2ms
memory: 6360kb
input:
1 12 100 0 11 90 0 100
output:
122.00000 3 0 100.00000 100.00000 1 11.00000 100.00000 0 11.00000 90.00000
result:
ok correct
Test #15:
score: 0
Accepted
time: 1ms
memory: 4204kb
input:
1 12 100 0 10 89 0 100
output:
122.00000 3 0 100.00000 100.00000 1 0.00000 89.00000 0 10.00000 89.00000
result:
ok correct
Test #16:
score: 0
Accepted
time: 1ms
memory: 4484kb
input:
2 1 2 1 5 1 1 3 6 3
output:
3.00000 1 0 5.00000 1.00000
result:
ok correct
Test #17:
score: 0
Accepted
time: 1ms
memory: 4288kb
input:
2 2 2 1 5 1 1 3 6 3
output:
3.00000 1 0 5.00000 1.00000
result:
ok correct
Test #18:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
1 2 1 1 5 3 7 2
output:
4.00000 3 0 1.00000 2.00000 1 5.00000 2.00000 0 5.00000 3.00000
result:
ok correct
Test #19:
score: 0
Accepted
time: 1ms
memory: 4348kb
input:
1 2 1 1 5 4 6 2
output:
4.00000 3 0 1.00000 2.00000 1 6.00000 4.00000 0 5.00000 4.00000
result:
ok correct
Test #20:
score: 0
Accepted
time: 2ms
memory: 7000kb
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.00000 1 3 76.00000 78.00000
result:
ok correct
Test #21:
score: 0
Accepted
time: 1ms
memory: 5912kb
input:
5 1 40 69 37 71 37 69 36 71 38 70 40 72 40 71
output:
1.00000 1 1 37.00000 71.00000
result:
ok correct
Test #22:
score: 0
Accepted
time: 1ms
memory: 5036kb
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.00000 1 3 86.00000 32.00000
result:
ok correct
Test #23:
score: 0
Accepted
time: 1ms
memory: 6584kb
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.00000 1 2 99.00000 36.00000
result:
ok correct
Test #24:
score: 0
Accepted
time: 1ms
memory: 4664kb
input:
4 1 19 37 18 32 18 36 21 36 19 33 22 34
output:
2.00000 2 0 19.00000 36.00000 1 18.00000 32.00000
result:
ok correct
Test #25:
score: 0
Accepted
time: 0ms
memory: 6892kb
input:
7 1 49 6 48 8 46 3 49 9 45 6 43 3 49 8 43 8 48 2
output:
1.00000 1 5 48.00000 8.00000
result:
ok correct
Test #26:
score: 0
Accepted
time: 2ms
memory: 6704kb
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.00000 3 5 76.00000 37.00000 6 81.00000 34.00000 7 74.00000 34.00000
result:
ok correct
Test #27:
score: 0
Accepted
time: 0ms
memory: 6520kb
input:
3 3 74 19 75 15 70 17 74 10 75 17
output:
4.00000 2 2 74.00000 15.00000 0 75.00000 15.00000
result:
ok correct
Test #28:
score: 0
Accepted
time: 1ms
memory: 6240kb
input:
6 1 38 6 35 3 32 13 34 4 37 4 28 10 37 12 35 14
output:
3.00000 3 0 37.00000 6.00000 3 35.00000 4.00000 0 35.00000 3.00000
result:
ok correct
Test #29:
score: 0
Accepted
time: 2ms
memory: 5076kb
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.23607 1 0 90.00000 52.00000
result:
ok correct
Test #30:
score: 0
Accepted
time: 1ms
memory: 6456kb
input:
3 1 28 85 24 87 23 94 29 87 23 86
output:
2.00000 2 0 29.00000 85.00000 2 24.00000 87.00000
result:
ok correct
Test #31:
score: 0
Accepted
time: 2ms
memory: 6028kb
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.00000 2 0 56.00000 69.00000 3 54.00000 77.00000
result:
ok correct
Test #32:
score: 0
Accepted
time: 2ms
memory: 7968kb
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.00000 3 0 70.00000 73.00000 1 78.00000 62.00000 19 62.00000 63.00000
result:
ok correct
Test #33:
score: -100
Wrong Answer
time: 2ms
memory: 8128kb
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:
3.00000 3 0 72.00000 55.00000 3 55.00000 76.00000 8 63.00000 68.00000
result:
wrong answer read 3.000000 but expected 2.000000, error = 1.000000