CSES - Datatähti 2022 loppu - Results
Submission details
Task:Sokkelo
Sender:Mahtimursu
Submission time:2022-01-22 13:46:40 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#20.01 s1, 2details
#30.01 s1, 2details
#4ACCEPTED0.06 s2details
#50.12 s2details
#60.11 s2details
#70.01 s1, 2details
#80.10 s2details
#90.09 s2details
#100.01 s1, 2details
#110.10 s2details
#120.01 s1, 2details
#130.09 s2details
#140.01 s1, 2details
#150.09 s2details
#16ACCEPTED0.01 s2details
#17ACCEPTED0.01 s2details

Code

#include <bits/stdc++.h>
typedef long long ll;
#define M 1000000007
#define N (1 << 18)
using namespace std;
string mp[1001];
bool vis[1001][1001];
bool vis2[1001][1001];
int dst[1001][1001];
int dirs[4][2] = {
{-1, 0},
{0, -1},
{1, 0},
{0, 1}
};
void dfs(int y, int x) {
if (vis[y][x]) return;
vis[y][x] = 1;
for (int k = 0; k < 4; ++k) {
int ny = y + dirs[k][0];
int nx = x + dirs[k][1];
if (mp[ny][nx] != '#') {
dfs(ny, nx);
}
}
}
void dfs2(int y, int x) {
if (vis2[y][x]) return;
vis2[y][x] = 1;
for (int k = 0; k < 4; ++k) {
int ny = y + dirs[k][0];
int nx = x + dirs[k][1];
if (mp[ny][nx] != '#') {
dfs2(ny, nx);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> mp[i];
}
pair<int, int> a = {-1, -1};
pair<int, int> b = {-1, -1};
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (mp[i][j] == 'A') {
a = {i, j};
}
else if (mp[i][j] == 'B') {
b = {i, j};
}
}
}
dfs(a.first, a.second);
if (vis[b.first][b.second]) {
cout << 1 << "\n";
return 0;
}
queue<pair<int, int>> q;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (!vis[i][j]) {
dst[i][j] = 1e9;
} else {
q.push({i, j});
}
cout << (dst[i][j] == 0 ? 0 : 1);
}
cout << endl;
}
while (!q.empty()) {
auto p = q.front(); q.pop();
int x = p.second;
int y = p.first;
for (int k = 0; k < 4; ++k) {
int nx = x + dirs[k][1];
int ny = y + dirs[k][0];
if (nx >= 0 && ny >= 0 && nx < m && ny < n && dst[y][x] + 1 < dst[ny][nx]) {
dst[ny][nx] = dst[y][x] + 1;
q.push({ny, nx});
}
}
}
dfs2(b.first, b.second);
int ans = 1e9;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (vis2[i][j]) {
ans = min(ans, dst[i][j]);
//cout << i << ", " << j << endl;
}
}
}
if (ans > n * m || ans < 2) exit(-1);
cout << ans << "\n";
return 0;
}

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:

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

correct output
2

user output
11111111111111111111
10000000000000000001
10000000000000000001
10000000000000000001
100000
...
Truncated

Test 3

Group: 1, 2

Verdict:

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

correct output
9

user output
11111111111111111111
10000000000000000001
10000000000000000001
10000000000000000001
100000
...
Truncated

Test 4

Group: 2

Verdict: ACCEPTED

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

correct output
1

user output
1

Test 5

Group: 2

Verdict:

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

correct output
2

user output
111111111111111111111111111111...
Truncated

Test 6

Group: 2

Verdict:

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

correct output
335

user output
111111111111111111111111111111...
Truncated

Test 7

Group: 1, 2

Verdict:

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

correct output
10

user output
11111111111111111111
11111011111111111111
11100000111111111111
11000000011111111111
110000
...
Truncated

Test 8

Group: 2

Verdict:

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

correct output
436

user output
111111111111111111111111111111...
Truncated

Test 9

Group: 2

Verdict:

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

correct output
2

user output
111111111111111111111111111111...
Truncated

Test 10

Group: 1, 2

Verdict:

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

correct output
2

user output
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
111000
...
Truncated

Test 11

Group: 2

Verdict:

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

correct output
2

user output
111111111111111111111111111111...
Truncated

Test 12

Group: 1, 2

Verdict:

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

correct output
2

user output
11111111111111111111
11111111110111111111
11111111110111111111
11111111110111111111
111111
...
Truncated

Test 13

Group: 2

Verdict:

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

correct output
2

user output
111111111111111111111111111111...
Truncated

Test 14

Group: 1, 2

Verdict:

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

correct output
12

user output
11111111111111111111
11111111110111111111
11111111110111111111
11111111110111111111
111111
...
Truncated

Test 15

Group: 2

Verdict:

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

correct output
502

user output
111111111111111111111111111111...
Truncated

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