QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#80000#2925. Parking LotperspectiveAC ✓2404ms69544kbC++235.2kb2023-02-21 16:42:202023-02-21 16:42:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-21 16:42:24]
  • 评测
  • 测评结果:AC
  • 用时:2404ms
  • 内存:69544kb
  • [2023-02-21 16:42:20]
  • 提交

answer

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define INP "input"
#define OUT "output"

/* some template */
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& a) {
    out << (int)a.size() << '\n';
    for (const auto& v : a) out << v << ' ';
    out << endl;
    return out;
}

template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<vector<T>>& a) {
    out << (int)a.size() << '\n';
    for (const auto& v : a) {
        for (const auto& value : v) out << value << ' ';
        out << endl;
    }
    return out;
}

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}
/* end template */

const long long INF_LL = 1e18;
const int INF = 1e9 + 100;
const long double EPS = 1e-9;
const int BLOCK = 550;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

void open_file() {
#ifdef THEMIS
    freopen(INP ".txt", "r", stdin);
    freopen(OUT ".txt", "w", stdout);
#endif  // THEMIS
}

const int maxN = 1e6 + 100;
const int MOD = 1e9 + 7;

/// Graham
struct Point {
    long long x, y;
    Point(){};
    Point(long long _x, long long _y) : x(_x), y(_y){};
    friend ostream& operator<<(ostream& os, const Point& A) {
        os << A.x << " " << A.y << '\n';
        return os;
    }
};

int S(Point A, Point B, Point C) {
    vector<Point> a = {A, B, C};
    a.push_back(A);
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        ans += (a[i + 1].x - a[i].x) * (a[i + 1].y + a[i].y);
    }
    return ans;
}

// dijkstra for minimize path
template <typename TEdge, typename TVertex>
void dijkstra(const vector<vector<pair<int, TEdge>>>& adj, int source, vector<TVertex>& d) {
    int n = (int)adj.size();

    d.resize(n);
    for (int i = 0; i < n; i++) d[i] = std::numeric_limits<TVertex>::max();  // initialize for each vertex
    d[source] = 0;                                                           /// initialize for vertex source

    typedef pair<TVertex, int> i2;
    priority_queue<i2, vector<i2>, std::greater<i2>> Q;
    Q.push({d[source], source});

    while ((int)Q.size() != 0) {
        i2 valueTop = Q.top();
        Q.pop();

        TVertex du = valueTop.first;
        int u = valueTop.second;
        if (abs(d[u] - du) > EPS) {  // or abs(d[u] - du) > EPS for double
            continue;
        }

        for (auto it : adj[u]) {
            int v = it.first;
            TEdge w = it.second;

            if (d[v] > d[u] + w) {  // if d[u] + w is better than d[v]
                d[v] = d[u] + w;
                Q.push({d[v], v});
            }
        }
    }
}

void sol() {
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    cin >> s;

    auto id = [&](int x, int y, int delta = 0) {
        return x * (m + delta) + y;
    };

    auto check = [&](int xL, int yL, int xR, int yR) {
        Point A(xL, yL), B(xR + 1, yR + 1);
        int x = xL, y = yL;
        while (x != xR || y != yR) {
            if (s[x][y] == '#') {
                return false;
            }
            int area = S(A, Point(x + 1, y + 1), B);
            if (area < 0)
                y++;
            else {
                if (area == 0) {
                    x++;
                    y++;
                } else
                    x++;
            }
        }
        return s[xR][yR] != '#';
    };

    vector<vector<pair<int, double>>> adj(n * (m + 1) + 2 * m);
    auto addEdge = [&](int u, int v, double d) {
        adj[u].push_back({v, d});
        adj[v].push_back({u, d});
    };
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int vertexL = id(i, j, 1);
            addEdge(vertexL, vertexL + 1, 1);
            addEdge(vertexL, vertexL + m + 1, 1);
            addEdge(vertexL + 1, vertexL + m + 2, 1);
            addEdge(vertexL + m + 1, vertexL + m + 2, 1);
            for (int u = i; u < n; u++) {
                for (int v = j; v < m; v++) {
                    if (check(i, j, u, v)) {
                        int vertexR = id(u, v, 1) + 2 + m;
                        double dist = sqrt((u - i + 1) * (u - i + 1) + (v - j + 1) * (v - j + 1));
                        addEdge(vertexL, vertexR, dist);
                    }
                }
            }
        }
    }

    vector<double> d;
    dijkstra(adj, id(0, 0), d);
    cout << fixed << setprecision(10) << d[id(n - 1, m - 1, 1) + 2 + m];
}

void solve() {
    clock_t start, end;
    start = clock();
    int T = 1;
    // cin >> T;
    int TestCase = 0;
    while (T--) {
        TestCase += 1;
        cerr << "Processing test = " << TestCase << '\n';
        // cout << "Case #" << TestCase << ": ";
        sol();
        // if (T) cout << '\n';
    }
    end = clock();
    cerr << "Time = " << (double)(end - start) / (double)CLOCKS_PER_SEC << '\n';
}

int main(int argc, char* argv[]) {
    // srand(time(nullptr));
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    open_file();
    solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3672kb

input:

1 1
.

output:

1.4142135624

result:

ok found '1.4142136', expected '1.4142136', error '0.0000000'

Test #2:

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

input:

1 1
#

output:

2.0000000000

result:

ok found '2.0000000', expected '2.0000000', error '0.0000000'

Test #3:

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

input:

1 3
.#.

output:

3.4142135624

result:

ok found '3.4142136', expected '3.4142136', error '0.0000000'

Test #4:

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

input:

1 3
##.

output:

3.4142135624

result:

ok found '3.4142136', expected '3.4142136', error '0.0000000'

Test #5:

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

input:

2 3
.#.
.#.

output:

3.8284271247

result:

ok found '3.8284271', expected '3.8284271', error '0.0000000'

Test #6:

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

input:

2 6
#..#.#
#.#..#

output:

6.4721359550

result:

ok found '6.4721360', expected '6.4721360', error '0.0000000'

Test #7:

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

input:

6 5
.####
#...#
#.##.
#.###
##...
####.

output:

8.2267727624

result:

ok found '8.2267728', expected '8.2267728', error '0.0000000'

Test #8:

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

input:

12 10
##########
##########
###....###
##########
#..####..#
###....###
#######.##
...#######
###....###
#######..#
###....###
##########

output:

18.9442719100

result:

ok found '18.9442719', expected '18.9442719', error '0.0000000'

Test #9:

score: 0
Accepted
time: 2404ms
memory: 69544kb

input:

50 50
..................................................
..................................................
..................................................
..................................................
..................................................
..........................................

output:

70.7106781187

result:

ok found '70.7106781', expected '70.7106781', error '0.0000000'

Test #10:

score: 0
Accepted
time: 89ms
memory: 8612kb

input:

13 47
...............................................
...............................................
...............................................
...............................................
...............................................
...............................................
.........

output:

48.7647413609

result:

ok found '48.7647414', expected '48.7647414', error '0.0000000'

Test #11:

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

input:

50 50
##################################################
##################################################
##################################################
##################################################
##################################################
#######################################...

output:

100.0000000000

result:

ok found '100.0000000', expected '100.0000000', error '0.0000000'

Test #12:

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

input:

47 13
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
#############
...

output:

60.0000000000

result:

ok found '60.0000000', expected '60.0000000', error '0.0000000'

Test #13:

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

input:

49 1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

output:

49.0102030194

result:

ok found '49.0102030', expected '49.0102030', error '0.0000000'

Test #14:

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

input:

49 1
.
.
#
#
#
.
.
.
.
.
#
#
#
#
#
#
#
#
#
#
.
.
.
.
#
.
.
.
.
#
#
#
.
#
#
.
.
#
#
#
#
#
.
#
#
.
.
.
.

output:

49.0990195136

result:

ok found '49.0990195', expected '49.0990195', error '0.0000000'

Test #15:

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

input:

3 45
.............................................
.............................................
.............................................

output:

45.0998891351

result:

ok found '45.0998891', expected '45.0998891', error '0.0000000'

Test #16:

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

input:

3 45
###..####.##.#.#.##..#.#############...##.###
##.###..#.##.#.##.#.#...#.......#...##..###.#
###...##..##........#..###.#...#..#.#.....#..

output:

45.4061553030

result:

ok found '45.4061553', expected '45.4061553', error '0.0000000'

Test #17:

score: 0
Accepted
time: 1986ms
memory: 54820kb

input:

50 50
..................................................
........#.........................................
..................................................
..................................................
..................................................
..........................................

output:

70.7106781187

result:

ok found '70.7106781', expected '70.7106781', error '0.0000000'

Test #18:

score: 0
Accepted
time: 85ms
memory: 8392kb

input:

13 47
......................................#........
...............................................
...........#.....#.............................
...............................................
...............................................
...............................................
.........

output:

48.7647413609

result:

ok found '48.7647414', expected '48.7647414', error '0.0000000'

Test #19:

score: 0
Accepted
time: 967ms
memory: 32556kb

input:

40 46
..............................................
......................#................#......
...........................#..................
............#.................................
..............................................
..............................................
...............

output:

60.9590026165

result:

ok found '60.9590026', expected '60.9590026', error '0.0000000'

Test #20:

score: 0
Accepted
time: 1029ms
memory: 23100kb

input:

50 50
........................#.........................
.......#.......#....#.........#.............#.....
...............#..................................
.........#...........#................#..#........
....#........#............................#....##.
....#.....#....................#.#........

output:

70.9811719495

result:

ok found '70.9811719', expected '70.9811719', error '0.0000000'

Test #21:

score: 0
Accepted
time: 59ms
memory: 5736kb

input:

47 13
..........#..
.............
.............
..........#..
....#....#...
...##........
...#......#..
.............
.............
.............
.............
.............
...........#.
.............
........#....
.............
.............
........#....
........#..#.
.............
.............
...

output:

48.7724812989

result:

ok found '48.7724813', expected '48.7724813', error '0.0000000'

Test #22:

score: 0
Accepted
time: 621ms
memory: 18444kb

input:

40 46
.......#...........#.#.......#................
.#..............................#........#....
...........................#..............#...
..............#...............................
.....................................#.......#
.#..........................#...........#.....
.......#.......

output:

61.1312087107

result:

ok found '61.1312087', expected '61.1312087', error '0.0000000'

Test #23:

score: 0
Accepted
time: 79ms
memory: 4448kb

input:

50 50
.#...###.#..#.#.....#.#..###..#.#..#.....###.##.#.
####..###..#...##..######.##..#####..##.###..##.##
#####..#..###..##..#.#..#.##...#.#####.##..#####.#
....##....#.#####.#.##.##....#.###.#...#.#.##.##.#
##.....#.##.########..##..#....#.##..#.##.##...#..
###.#..##.##.#####.##..##.#.#.#.#.#..##...

output:

74.4641296411

result:

ok found '74.4641296', expected '74.4641296', error '0.0000000'

Test #24:

score: 0
Accepted
time: 55ms
memory: 4408kb

input:

47 43
#.#...#.#...##.#.##.##.#.#....#.####.#..#..
.####....#..#..#..#.#...####...#.#.......##
.#.#####.#..#..#..#####.#####.#.#.###..##.#
.###.#####.#....######...#.#.#.#..##.###...
.#.###.......#..#####..#######..#..#....#.#
#..####..#.##.#..#..##.#.#.###.####.###.#..
.#.##.#####.#.##.##..##.#.##.....

output:

67.7300785565

result:

ok found '67.7300786', expected '67.7300786', error '0.0000000'

Test #25:

score: 0
Accepted
time: 59ms
memory: 4300kb

input:

44 48
##....###...#.#..##....###..##.##.....###.###...
#..##..#..#........###.###....##.##..##...#.###.
.#....###...#.......#.###..##..##...#.####.#....
.#.#.###...#.#..#..###..##....###..####....#.#..
...#.#.#...##..#..###.###.#.#..#...#.###..##.#..
##.#.###...####.#..#..#####.##..#.##.##.........
...

output:

69.0597016892

result:

ok found '69.0597017', expected '69.0597017', error '0.0000000'

Test #26:

score: 0
Accepted
time: 27ms
memory: 4180kb

input:

50 50
..#.####..#.##########..#######.####.#.#.#########
....#####.##..#########.#######.##.##..##.####..#.
##.#####.##.#.###.##..#.#.#####..#######.###.#####
.##..######..#.########.#..######..######.######.#
##.#################.#####.##..##.########.#######
###.#.#..##.#########.#.###.####.##.###...

output:

81.5870286298

result:

ok found '81.5870286', expected '81.5870286', error '0.0000000'

Test #27:

score: 0
Accepted
time: 33ms
memory: 4236kb

input:

50 50
#####.#######.##..#...########..#####.###..###.#.#
###.#####.#.##....#....#.###.#####.###.###.##.##.#
..#.######..#..##..#..######.####.#.#########..##.
#####..####.###.##.########.#.###########.###.###.
###.#######.###....##########..###.##.#.###.#..###
.##..##.##.###.##.#########.#.###.#####...

output:

80.7101342555

result:

ok found '80.7101343', expected '80.7101343', error '0.0000000'

Test #28:

score: 0
Accepted
time: 30ms
memory: 4236kb

input:

50 50
#..#####..######..##.#####.###########.##.###.###.
#.######.##.###.##.####.###.#####.###.#.##...#####
#########.##..##.####...#.##########.#####.#######
########...#..#..#####.##.#####.##.###.#..#######.
.##############.######..###.#..#####.######.####.#
##.##.#.###.##.#.#####.#..##.###.##.###...

output:

81.3350927276

result:

ok found '81.3350927', expected '81.3350927', error '0.0000000'

Test #29:

score: 0
Accepted
time: 31ms
memory: 4228kb

input:

50 50
##.########.#####################.#######..######.
###.#####.##.###.########...####..##########.#..##
##.#.##.##...##.###########.#####.####.##.######.#
#..#####..###.#.##.######.##########.###.###.#####
###.####..########.#.######.###.####.########..###
######.##.#######.#######.#..######...#...

output:

80.7229800402

result:

ok found '80.7229800', expected '80.7229800', error '0.0000000'

Test #30:

score: 0
Accepted
time: 14ms
memory: 4248kb

input:

50 50
#########.##########.##.############.#######.#####
#########################.#######.########.#######
..###########.#######.#####.#######..#######.##.##
##########.##################.###################.
############.#########.################..#.#######
#########.##########.######.##.########...

output:

86.7339665681

result:

ok found '86.7339666', expected '86.7339666', error '0.0000000'

Test #31:

score: 0
Accepted
time: 10ms
memory: 4168kb

input:

50 50
########..#############.###################..#####
#######.############.############.#####.##########
###########.#########################..#####.##.##
#####.###############.##################.#####.###
################..############..#########.########
#############################.######.##...

output:

86.9411722059

result:

ok found '86.9411722', expected '86.9411722', error '0.0000000'

Test #32:

score: 0
Accepted
time: 15ms
memory: 4168kb

input:

50 50
#####..#.##.######.#########..#######.##..########
###################...####################.######.
.####.######.###########.#######################.#
################.##########.##..################.#
######.#.#################.#########.#########.#.#
##########..######.#############.######...

output:

86.4001160327

result:

ok found '86.4001160', expected '86.4001160', error '0.0000000'

Test #33:

score: 0
Accepted
time: 11ms
memory: 4256kb

input:

50 50
.###############.#########.##.###.#########.######
#####.###..##############.###########.#.#########.
################.#####.##############.#######.####
#######..###.####################.#.#####.###..###
#####.#.####.#####.####.#.######################.#
#######.################.##.#####.##.##...

output:

86.4001160327

result:

ok found '86.4001160', expected '86.4001160', error '0.0000000'

Test #34:

score: 0
Accepted
time: 11ms
memory: 4144kb

input:

50 50
....##############################################
###.....##########################################
#######.....######################################
###########.....##################################
###############....###############################
###################.###################...

output:

74.2911870736

result:

ok found '74.2911871', expected '74.2911871', error '0.0000000'

Test #35:

score: 0
Accepted
time: 11ms
memory: 4148kb

input:

50 50
.#################################################
.#################################################
..################################################
#.################################################
#.################################################
#..####################################...

output:

74.8604442675

result:

ok found '74.8604443', expected '74.8604443', error '0.0000000'

Test #36:

score: 0
Accepted
time: 10ms
memory: 4240kb

input:

50 50
.#################################################
..################################################
#..###############################################
##..##############################################
###..#############################################
####.##################################...

output:

72.6800364344

result:

ok found '72.6800364', expected '72.6800364', error '0.0000000'

Test #37:

score: 0
Accepted
time: 11ms
memory: 4132kb

input:

50 50
.#################################################
..################################################
#.################################################
#..###############################################
##..##############################################
###.###################################...

output:

71.9011737346

result:

ok found '71.9011737', expected '71.9011737', error '0.0000000'

Test #38:

score: 0
Accepted
time: 16ms
memory: 4228kb

input:

50 50
.#################################################
.#################################################
.#################################################
.#################################################
.#################################################
.######################################...

output:

80.0738471351

result:

ok found '80.0738471', expected '80.0738471', error '0.0000000'

Test #39:

score: 0
Accepted
time: 10ms
memory: 4184kb

input:

50 50
.#################################################
..################################################
#.################################################
#..###############################################
##.###############################################
##..###################################...

output:

76.6029900730

result:

ok found '76.6029901', expected '76.6029901', error '0.0000000'

Test #40:

score: 0
Accepted
time: 14ms
memory: 4120kb

input:

50 50
...###############################################
##....############################################
#####...##########################################
########...#######################################
##########....####################################
#############...#######################...

output:

76.7843160097

result:

ok found '76.7843160', expected '76.7843160', error '0.0000000'

Test #41:

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

input:

50 50
.#################################################
#.################################################
##.###############################################
###.##############################################
####.#############################################
#####.#################################...

output:

75.9965204027

result:

ok found '75.9965204', expected '75.9965204', error '0.0000000'

Test #42:

score: 0
Accepted
time: 9ms
memory: 4124kb

input:

50 50
.#################################################
#.################################################
##.###############################################
###.##############################################
####.#############################################
#####.#################################...

output:

72.5743073617

result:

ok found '72.5743074', expected '72.5743074', error '0.0000000'

Test #43:

score: 0
Accepted
time: 5ms
memory: 4132kb

input:

50 50
.#################################################
#.################################################
##.###############################################
###.##############################################
####.#############################################
#####.#################################...

output:

76.4090909654

result:

ok found '76.4090910', expected '76.4090910', error '0.0000000'

Test #44:

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

input:

50 50
.#################################################
#.################################################
##.###############################################
###.##############################################
####.#############################################
#####.#################################...

output:

73.4364937471

result:

ok found '73.4364937', expected '73.4364937', error '0.0000000'

Test #45:

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

input:

50 50
.#################################################
#.################################################
##.###############################################
###.##############################################
####.#############################################
#####.#################################...

output:

73.7681785004

result:

ok found '73.7681785', expected '73.7681785', error '0.0000000'

Test #46:

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

input:

50 50
.#################################################
#.################################################
#..###############################################
##..##############################################
###..#############################################
####..#################################...

output:

70.8291472641

result:

ok found '70.8291473', expected '70.8291473', error '0.0000000'

Test #47:

score: 0
Accepted
time: 22ms
memory: 4388kb

input:

50 50
.#################################################
#..###############################################
##..##############################################
###..#############################################
####..############################################
#####..################################...

output:

70.7337485033

result:

ok found '70.7337485', expected '70.7337485', error '0.0000000'

Test #48:

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

input:

50 50
.#################################################
#.################################################
#..###############################################
##..##############################################
###..#############################################
####..#################################...

output:

71.4412021172

result:

ok found '71.4412021', expected '71.4412021', error '0.0000000'

Test #49:

score: 0
Accepted
time: 13ms
memory: 4148kb

input:

50 50
........................##########################
#######################........................###
###############################################.##
###############################################.##
###############################################.##
#######################################...

output:

95.2492341237

result:

ok found '95.2492341', expected '95.2492341', error '0.0000000'

Test #50:

score: 0
Accepted
time: 13ms
memory: 4140kb

input:

50 50
.............#####################################
#############.............########################
##########################.............###########
#######################################.##########
#######################################.##########
#######################################...

output:

87.3995487821

result:

ok found '87.3995488', expected '87.3995488', error '0.0000000'

Test #51:

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

input:

4 4
..#.
.#.#
###.
.#..

output:

5.8863495174

result:

ok found '5.8863495', expected '5.8863495', error '0.0000000'

Test #52:

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

input:

2 2
##
##

output:

4.0000000000

result:

ok found '4.0000000', expected '4.0000000', error '0.0000000'