CSES - Datatähti 2022 loppu - Results
Submission details
Task:Sokkelo
Sender:cowperso
Submission time:2022-01-22 15:27:02 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s1, 2details
#30.01 s1, 2details
#4ACCEPTED0.41 s2details
#5ACCEPTED0.21 s2details
#60.15 s2details
#7ACCEPTED0.01 s1, 2details
#8ACCEPTED0.26 s2details
#9ACCEPTED0.23 s2details
#10ACCEPTED0.01 s1, 2details
#110.29 s2details
#12ACCEPTED0.01 s1, 2details
#13ACCEPTED0.27 s2details
#14ACCEPTED0.01 s1, 2details
#15ACCEPTED0.26 s2details
#16ACCEPTED0.01 s2details
#17ACCEPTED0.01 s2details

Compiler report

input/code.cpp: In function 'void haku(int32_t, int32_t)':
input/code.cpp:59:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (y < 0 || y > n - 1 || x < 0 || x > m - 1)
                ~~^~~~~~~
input/code.cpp:59:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (y < 0 || y > n - 1 || x < 0 || x > m - 1)
                                      ~~^~~~~~~

Code

#include <iostream>
#include <queue>
#include <vector>

bool kartta[1000][1000];
int64_t e[1000][1000];
bool z[1000][1000];

uint32_t n, m;

std::vector<std::pair<std::pair<uint32_t, uint32_t>, int64_t>>
naap(uint32_t y, uint32_t x) {
  std::vector<std::pair<std::pair<uint32_t, uint32_t>, int64_t>> res = {};
  if (kartta[y][x]) {
    if (y != 0 && kartta[y - 1][x]) {
      res.push_back({{y - 1, x}, 100000});
    }
    if (y != n - 1 && kartta[y + 1][x]) {
      res.push_back({{y + 1, x}, 100000});
    }
    if (x != 0 && kartta[y][x - 1]) {
      res.push_back({{y, x - 1}, 100000});
    }
    if (x != m - 1 && kartta[y][x + 1]) {
      res.push_back({{y, x + 1}, 100000});
    }
  } else {
    if (y != 0 && !kartta[y - 1][x]) {
      res.push_back({{y - 1, x}, 1});
    }
    if (y != 0 && kartta[y - 1][x]) {
      res.push_back({{y - 1, x}, 100000});
    }
    if (y != n - 1 && !kartta[y + 1][x]) {
      res.push_back({{y + 1, x}, 1});
    }
    if (y != n - 1 && kartta[y + 1][x]) {
      res.push_back({{y + 1, x}, 100000});
    }
    if (x != 0 && !kartta[y][x - 1]) {
      res.push_back({{y, x - 1}, 1});
    }
    if (x != 0 && kartta[y][x - 1]) {
      res.push_back({{y, x - 1}, 100000});
    }
    if (x != m - 1 && !kartta[y][x + 1]) {
      res.push_back({{y, x + 1}, 1});
    }
    if (x != m - 1 && kartta[y][x + 1]) {
      res.push_back({{y, x + 1}, 100000});
    }
  }
  return res;
}

int64_t fres = INT64_MAX;
bool z2[1000][1000];
void haku(int32_t y, int32_t x) {
  if (y < 0 || y > n - 1 || x < 0 || x > m - 1)
    return;
  if (kartta[y][x])
    return;
  if (z2[y][x])
    return;
  z2[y][x] = true;
  fres = std::min(
      fres, std::min(e[y][x], std::min(std::min(e[y - 1][x], e[y + 1][x]),
                                       std::min(e[y][x - 1], e[y][x + 1]))));
  std::vector<std::pair<int32_t, int32_t>> diffs = {
      {1, 0}, {-1, 0}, {0, -1}, {0, 1}};
  for (auto diff : diffs) {
    haku(y + diff.first, x + diff.second);
  }
}

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

  std::cin >> n >> m;

  uint32_t ax = 0, ay = 0;
  uint32_t bx = 0, by = 0;
  for (uint32_t i = 0; i < n; ++i) {
    for (uint32_t j = 0; j < m; ++j) {
      char c;
      std::cin >> c;
      switch (c) {
      case '#':
        kartta[i][j] = true;
        break;
      case 'A':
        ax = j;
        ay = i;
        break;
      case 'B':
        bx = j;
        by = i;
        break;
      }
    }
  }

  for (uint32_t i = 0; i < n; ++i) {
    for (uint32_t j = 0; j < m; ++j) {
      e[i][j] = INT64_C(1) << 60;
    }
  }
  e[ay][ax] = 0;
  std::priority_queue<std::pair<int64_t, std::pair<uint32_t, uint32_t>>> q = {};
  q.push({0, {ay, ax}});
  while (!q.empty()) {
    uint32_t y = q.top().second.first;
    uint32_t x = q.top().second.second;
    q.pop();
    if (z[y][x])
      continue;
    z[y][x] = true;
    for (auto b : naap(y, x)) {
      if (e[y][x] + b.second < e[b.first.first][b.first.second]) {
        e[b.first.first][b.first.second] = e[y][x] + b.second;
        q.push({-e[b.first.first][b.first.second], b.first});
      }
    }
  }

  haku(by, bx);
  if (fres >= 100000) {
    std::cout << fres / 100000 + 1 << '\n';
  } else {
    std::cout << "1\n";
  }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
20 20
####################
#A.................#
#..................#
#..................#
...

correct output
1

user output
1

Test 2

Group: 1, 2

Verdict: ACCEPTED

input
20 20
####################
#A.................#
#..................#
#..................#
...

correct output
2

user output
2

Test 3

Group: 1, 2

Verdict:

input
20 20
####################
#A.................#
#..................#
#..................#
...

correct output
9

user output
11

Test 4

Group: 2

Verdict: ACCEPTED

input
1000 1000
##############################...

correct output
1

user output
1

Test 5

Group: 2

Verdict: ACCEPTED

input
1000 1000
##############################...

correct output
2

user output
2

Test 6

Group: 2

Verdict:

input
1000 1000
##############################...

correct output
335

user output
337

Test 7

Group: 1, 2

Verdict: ACCEPTED

input
20 20
####################
#####.##############
###.....############
##.......###########
...

correct output
10

user output
10

Test 8

Group: 2

Verdict: ACCEPTED

input
1000 1000
##############################...

correct output
436

user output
436

Test 9

Group: 2

Verdict: ACCEPTED

input
1000 1000
##############################...

correct output
2

user output
2

Test 10

Group: 1, 2

Verdict: ACCEPTED

input
20 20
####################
#B................##
#################.##
#################.##
...

correct output
2

user output
2

Test 11

Group: 2

Verdict:

input
1000 1000
##############################...

correct output
2

user output
3

Test 12

Group: 1, 2

Verdict: ACCEPTED

input
20 20
####################
##########A#########
##########.#########
##########.#########
...

correct output
2

user output
2

Test 13

Group: 2

Verdict: ACCEPTED

input
1000 1000
##############################...

correct output
2

user output
2

Test 14

Group: 1, 2

Verdict: ACCEPTED

input
20 20
####################
##########A#########
##########.#########
##########.#########
...

correct output
12

user output
12

Test 15

Group: 2

Verdict: ACCEPTED

input
1000 1000
##############################...

correct output
502

user output
502

Test 16

Group: 2

Verdict: ACCEPTED

input
3 1000
##############################...

correct output
1

user output
1

Test 17

Group: 2

Verdict: ACCEPTED

input
1000 3
###
#A#
#.#
#.#
...

correct output
1

user output
1