QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790756#2925. Parking LotowlpawAC ✓1256ms4128kbC++231.7kb2024-11-28 15:13:002024-11-28 15:13:03

Judging History

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

  • [2024-11-28 15:13:03]
  • 评测
  • 测评结果:AC
  • 用时:1256ms
  • 内存:4128kb
  • [2024-11-28 15:13:00]
  • 提交

answer

#pragma GCC optimize("O2,unroll-loops")
#include <bits/stdc++.h>

using f64 = double;
using TUP = std::tuple<f64, int, int>;

const int MAX_N = 55;

int N, M;
char mp[MAX_N][MAX_N];
int s[MAX_N][MAX_N];
f64 d[MAX_N][MAX_N];

inline f64 dist(int x1, int y1, int x2, int y2) {
  int dx = x2 - x1, dy = y2 - y1;
  return sqrt(dx * dx + dy * dy);
}

bool check(int x1, int y1, int x2, int y2) {
  for (int i = x1 + 1; i <= x2; ++i)
    for (int j = y1 + 1; j <= y2; ++j)
      if (mp[i][j] == '#') {
        f64 k1 = i - 1 == x1 ? 1e9 : (j - y1) * 1.0 / (i - 1 - x1);
        f64 k2 = x2 == x1 ? 1e9 : (y2 - y1) * 1.0 / (x2 - x1);
        f64 k3 = i == x1 ? 1e9 : (j - 1 - y1) * 1.0 / (i - x1);
        if (k1 >= k2 && k2 >= k3) return false;
      }

  return true;
}

void Dijkstra() {
  for (int i = 0; i <= N; ++i)
    for (int j = 0; j <= M; ++j)
      d[i][j] = 1e9;

  std::priority_queue<TUP, std::vector<TUP>, std::greater<TUP>> heap;
  heap.emplace(d[0][0] = 0, 0, 0);

  while (!heap.empty()) {
    auto [dd, x, y] = heap.top();
    heap.pop();

    for (int i = x; i <= N; ++i)
      for (int j = y; j <= M; ++j)
        if (i != x || j != y)
          if (x == i || y == j || check(x, y, i, j))
            if (f64 td = dd + dist(x, y, i, j); td < d[i][j])
              heap.emplace(d[i][j] = td, i, j);
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  std::cin >> N >> M;

  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j) {
      std::cin >> mp[i][j];
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (mp[i][j] == '#');
    }

  Dijkstra();

  std::fixed(std::cout).precision(7);
  std::cout << d[N][M] << '\n';
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1
.

output:

1.4142136

result:

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

Test #2:

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

input:

1 1
#

output:

2.0000000

result:

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

Test #3:

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

input:

1 3
.#.

output:

3.4142136

result:

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

Test #4:

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

input:

1 3
##.

output:

3.4142136

result:

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

Test #5:

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

input:

2 3
.#.
.#.

output:

3.8284271

result:

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

Test #6:

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

input:

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

output:

6.4721360

result:

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

Test #7:

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

input:

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

output:

8.2267728

result:

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

Test #8:

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

input:

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

output:

18.9442719

result:

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

Test #9:

score: 0
Accepted
time: 199ms
memory: 3932kb

input:

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

output:

70.7106781

result:

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

Test #10:

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

input:

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

output:

48.7647414

result:

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

Test #11:

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

input:

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

output:

100.0000000

result:

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

Test #12:

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

input:

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

output:

60.0000000

result:

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

Test #13:

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

input:

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

output:

49.0102030

result:

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

Test #14:

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

input:

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

output:

49.0990195

result:

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

Test #15:

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

input:

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

output:

45.0998891

result:

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

Test #16:

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

input:

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

output:

45.4061553

result:

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

Test #17:

score: 0
Accepted
time: 472ms
memory: 4008kb

input:

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

output:

70.7106781

result:

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

Test #18:

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

input:

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

output:

48.7647414

result:

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

Test #19:

score: 0
Accepted
time: 221ms
memory: 4056kb

input:

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

output:

60.9590026

result:

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

Test #20:

score: 0
Accepted
time: 1256ms
memory: 4060kb

input:

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

output:

70.9811719

result:

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

Test #21:

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

input:

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

output:

48.7724813

result:

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

Test #22:

score: 0
Accepted
time: 410ms
memory: 4052kb

input:

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

output:

61.1312087

result:

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

Test #23:

score: 0
Accepted
time: 354ms
memory: 3976kb

input:

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

output:

74.4641296

result:

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

Test #24:

score: 0
Accepted
time: 204ms
memory: 4052kb

input:

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

output:

67.7300786

result:

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

Test #25:

score: 0
Accepted
time: 215ms
memory: 4056kb

input:

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

output:

69.0597017

result:

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

Test #26:

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

input:

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

output:

81.5870286

result:

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

Test #27:

score: 0
Accepted
time: 169ms
memory: 4060kb

input:

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

output:

80.7101343

result:

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

Test #28:

score: 0
Accepted
time: 155ms
memory: 4036kb

input:

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

output:

81.3350927

result:

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

Test #29:

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

input:

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

output:

80.7229800

result:

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

Test #30:

score: 0
Accepted
time: 80ms
memory: 4004kb

input:

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

output:

86.7339666

result:

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

Test #31:

score: 0
Accepted
time: 78ms
memory: 4060kb

input:

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

output:

86.9411722

result:

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

Test #32:

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

input:

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

output:

86.4001160

result:

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

Test #33:

score: 0
Accepted
time: 97ms
memory: 4060kb

input:

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

output:

86.4001160

result:

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

Test #34:

score: 0
Accepted
time: 142ms
memory: 4056kb

input:

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

output:

74.2911871

result:

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

Test #35:

score: 0
Accepted
time: 127ms
memory: 3996kb

input:

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

output:

74.8604443

result:

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

Test #36:

score: 0
Accepted
time: 133ms
memory: 3956kb

input:

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

output:

72.6800364

result:

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

Test #37:

score: 0
Accepted
time: 128ms
memory: 4052kb

input:

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

output:

71.9011737

result:

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

Test #38:

score: 0
Accepted
time: 117ms
memory: 3996kb

input:

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

output:

80.0738471

result:

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

Test #39:

score: 0
Accepted
time: 127ms
memory: 4060kb

input:

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

output:

76.6029901

result:

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

Test #40:

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

input:

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

output:

76.7843160

result:

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

Test #41:

score: 0
Accepted
time: 126ms
memory: 4072kb

input:

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

output:

75.9965204

result:

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

Test #42:

score: 0
Accepted
time: 121ms
memory: 3948kb

input:

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

output:

72.5743074

result:

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

Test #43:

score: 0
Accepted
time: 117ms
memory: 4036kb

input:

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

output:

76.4090910

result:

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

Test #44:

score: 0
Accepted
time: 117ms
memory: 4060kb

input:

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

output:

73.4364937

result:

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

Test #45:

score: 0
Accepted
time: 132ms
memory: 3992kb

input:

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

output:

73.7681785

result:

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

Test #46:

score: 0
Accepted
time: 144ms
memory: 4076kb

input:

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

output:

70.8291473

result:

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

Test #47:

score: 0
Accepted
time: 142ms
memory: 3976kb

input:

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

output:

70.7337485

result:

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

Test #48:

score: 0
Accepted
time: 133ms
memory: 4128kb

input:

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

output:

71.4412021

result:

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

Test #49:

score: 0
Accepted
time: 87ms
memory: 3976kb

input:

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

output:

95.2492341

result:

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

Test #50:

score: 0
Accepted
time: 108ms
memory: 3988kb

input:

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

output:

87.3995488

result:

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

Test #51:

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

input:

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

output:

5.8863495

result:

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

Test #52:

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

input:

2 2
##
##

output:

4.0000000

result:

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