CSES - Datatähti 2022 loppu - Results
Submission details
Task:Sokkelo
Sender:lain
Submission time:2022-01-22 14:15:48 +0200
Language:C++ (C++17)
Status:READY
Result:28
Feedback
groupverdictscore
#1ACCEPTED28
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s1, 2details
#3ACCEPTED0.01 s1, 2details
#4ACCEPTED0.07 s2details
#5--2details
#6--2details
#7ACCEPTED0.01 s1, 2details
#8--2details
#9--2details
#10ACCEPTED0.01 s1, 2details
#11--2details
#12ACCEPTED0.01 s1, 2details
#13ACCEPTED0.49 s2details
#14ACCEPTED0.01 s1, 2details
#15ACCEPTED0.26 s2details
#16ACCEPTED0.01 s2details
#17ACCEPTED0.01 s2details

Code

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pb push_back
#define vc vector
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define tra(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()

template <typename... T> void get(T &...args) { ((cin >> args), ...); }
template <typename... T> void pri(T &&...args) { ((cout << args << " "), ...); }
template <typename... T> void pril(T &&...args) {
  ((cout << args << " "), ...);
  cout << '\n';
}

using ll = long long;
using vi = vc<int>;
using vll = vc<ll>;
using pi = pair<int, int>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int N = 1010;

char grid[N][N];
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, 1, 0, -1};
int n, m;

void bfs(vector<vector<int>> &vis, pi start) {
  queue<pi> q;
  q.push(start);
  vis[start.F][start.S] = 1;

  while (!q.empty()) {
    auto s = q.front();
    q.pop();
    rep(i, 0, 4) {
      pi ne = {s.F + x[i], s.S + y[i]};
      if (ne.F < 0 || ne.F >= n || ne.S < 0 || ne.S >= m)
        continue;
      if (vis[ne.F][ne.S] == 1)
        continue;
      if (grid[ne.F][ne.S] == '#')
        continue;
      vis[ne.F][ne.S] = 1;
      q.push(ne);
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  get(n, m);

  pi a;
  pi b;
  rep(i, 0, n) {
    rep(j, 0, m) {
      get(grid[i][j]);
      if (grid[i][j] == 'A') {
        a = {i, j};
      } else if (grid[i][j] == 'B') {
        b = {i, j};
      }
    }
  }
  vc<vi> vis_a(n, vi(m, 0));
  bfs(vis_a, a);
  vc<vi> vis_b(n, vi(m, 0));
  bfs(vis_b, b);

  int ans = INT_MAX;
  if (vis_a[b.F][b.S]) {
    pril(1);
    return 0;
  } else {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (vis_a[i][j]) {
          for (int k = 0; k < n; ++k) {
            for (int z = 0; z < m; ++z) {
              if (vis_b[k][z]) {
                ans = min(ans, abs(i - k) + abs(j - z));
              }
            }
          }
        }
      }
    }
  }

  pril(ans);
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

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

correct output
1

user output

Test 2

Group: 1, 2

Verdict: ACCEPTED

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

correct output
2

user output

Test 3

Group: 1, 2

Verdict: ACCEPTED

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

correct output
9

user output

Test 4

Group: 2

Verdict: ACCEPTED

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

correct output
1

user output

Test 5

Group: 2

Verdict:

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

correct output
2

user output
(empty)

Test 6

Group: 2

Verdict:

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

correct output
335

user output
(empty)

Test 7

Group: 1, 2

Verdict: ACCEPTED

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

correct output
10

user output
10 

Test 8

Group: 2

Verdict:

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

correct output
436

user output
(empty)

Test 9

Group: 2

Verdict:

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

correct output
2

user output
(empty)

Test 10

Group: 1, 2

Verdict: ACCEPTED

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

correct output
2

user output

Test 11

Group: 2

Verdict:

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

correct output
2

user output
(empty)

Test 12

Group: 1, 2

Verdict: ACCEPTED

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

correct output
2

user output

Test 13

Group: 2

Verdict: ACCEPTED

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

correct output
2

user output

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

Test 17

Group: 2

Verdict: ACCEPTED

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

correct output
1

user output