CSES - Datatähti 2022 loppu - Results
Submission details
Task:Sokkelo
Sender:cowperso
Submission time:2022-01-22 13:52:25 +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.26 s2details
#5ACCEPTED0.25 s2details
#60.25 s2details
#7ACCEPTED0.01 s1, 2details
#8ACCEPTED0.27 s2details
#9ACCEPTED0.31 s2details
#10ACCEPTED0.01 s1, 2details
#110.34 s2details
#12ACCEPTED0.01 s1, 2details
#13ACCEPTED0.25 s2details
#14ACCEPTED0.01 s1, 2details
#15ACCEPTED0.26 s2details
#16ACCEPTED0.01 s2details
#17ACCEPTED0.01 s2details

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 = {};
  bool tm = kartta[y][x];
  if (y != 0) {
    res.push_back({{y - 1, x}, (tm || kartta[y - 1][x]) * 100000 + 1});
  }
  if (y != n - 1) {
    res.push_back({{y + 1, x}, (tm || kartta[y + 1][x]) * 100000 + 1});
  }
  if (x != 0) {
    res.push_back({{y, x - 1}, (tm || kartta[y][x - 1]) * 100000 + 1});
  }
  if (x != m - 1) {
    res.push_back({{y, x + 1}, (tm || kartta[y][x + 1]) * 100000 + 1});
  }
  return res;
}

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});
      }
    }
  }

  if (e[by][bx] >= 100000) {
    std::cout << e[by][bx] / 100000 << '\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
4

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
4

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