QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#171444#7184. Transport Plusesucup-team859#RE 10ms4224kbC++174.1kb2023-09-09 16:59:542023-09-09 17:00:56

Judging History

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

  • [2023-09-09 17:00:56]
  • 评测
  • 测评结果:RE
  • 用时:10ms
  • 内存:4224kb
  • [2023-09-09 16:59:54]
  • 提交

answer

#include <bits/stdc++.h>

#define lsb(x) (x & (-x))

using ull = unsigned long long;
using ll = long long;

using namespace std;

constexpr double INF = 1e10;
constexpr int MAXX = 100;

double dist[MAXX + 1][MAXX + 1];

double best[MAXX + 1][MAXX + 1];
bool vis[MAXX + 1][MAXX + 1];

struct Move {
    int x, y;
    int id;
};

Move from[MAXX + 1][MAXX + 1];


int main() {
#ifdef HOME
    ifstream cin("input.in");
    ofstream cout("output.out");
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n, t;
    cin >> n >> t;

    int sx, sy, dx, dy;
    cin >> sx >> sy >> dx >> dy;

    vector<int> x(n + 1), y(n + 1); 
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }

    vector<pair<int, int>> primeDir;
    for (int a = 0; a <= MAXX; a++) {
        for (int b = 0; b <= MAXX; b++) {
            best[a][b] = INF;
            dist[a][b] = sqrt(a * a + b * b);

            if (__gcd(a, b) == 1) {
                primeDir.push_back({a, b});
            }
        }
    }

    best[sx][sy] = 0;

    while (true) {
        vector<pair<int, int>> pts;

        double mn = INF;
        for (int x = 0; x <= MAXX; x++) {
            for (int y = 0; y <= MAXX; y++) {
                if (!vis[x][y]) {
                    if (mn > best[x][y]) {
                        mn = best[x][y];
                        pts.clear();
                        pts.push_back({x, y});
                    } else if (mn == best[x][y]) {
                        pts.push_back({x, y});
                    }
                }
            }
        }

        for (auto p : pts) {
            vis[p.first][p.second] = true;

            if (p.first == dx && p.second == dy) {

                cout << fixed << setprecision(10) << best[dx][dy] << "\n";

                vector<Move> sol;
                int tx = dx, ty = dy;
                while (!(tx == sx && ty == sy)) {
                    auto curr = from[tx][ty];
                    sol.push_back(from[tx][ty]);
                    tx = curr.x;
                    ty = curr.y;
                }

                cout << sol.size() << "\n";

                reverse(sol.begin(), sol.end());
                for (int i = 1; i < (int)sol.size(); i++) {
                    cout << sol[i - 1].id << " " << sol[i].x << " " << sol[i].y << "\n";
                }
                cout << sol.back().id << " " << dx << " " << dy << "\n";

                return 0;
            }

            auto Go = [&](pair<int, int> p, pair<int, int> dir, double cost) {
                int x = p.first + dir.first;
                int y = p.second + dir.second;
                if (x >= 0 && x <= MAXX && y >= 0 && y <= MAXX && best[x][y] > mn + cost) {
                    best[x][y] = mn + cost;
                    from[x][y] = {p.first, p.second, 0};
                }
            };

            for (auto dir : primeDir) {
                double cost = dist[dir.first][dir.second];
                Go(p, dir, cost);
                Go(p, {dir.first, -dir.second}, cost);
                Go(p, {-dir.first, dir.second}, cost);
                Go(p, {-dir.first, -dir.second}, cost);
            }

            for (int i = 1; i <= n; i++) {
                if (x[i] == p.first || y[i] == p.second) {
                    for (int newy = 0; newy <= MAXX; newy++) {
                        if (best[x[i]][newy] > mn + t) {
                            best[x[i]][newy] = mn + t;
                            from[x[i]][newy] = {p.first, p.second, i};
                        }
                    }
                    for (int newx = 0; newx <= MAXX; newx++) {
                        // if (p.first == 1 && p.second == 1) {
                        //     cerr << mn + t << " " << best[newx][y[i]] << "\n";
                        // }
                        if (best[newx][y[i]] > mn + t) {
                            best[newx][y[i]] = mn + t;
                            from[newx][y[i]] = {p.first, p.second, i};
                        }
                    }
                }
            }
        }
    }

    return 0;
}

详细

Test #1:

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

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: 10ms
memory: 4224kb

input:

2 1
1 1
6 1
1 3
6 3

output:

2.0000000000
2
1 0 3
2 6 1

result:

ok correct

Test #3:

score: -100
Runtime Error

input:

0 0
1 1
1 1

output:


result: