CSES - Datatähti 2022 loppu - Results
Submission details
Task:Sokkelo
Sender:Anttono
Submission time:2022-01-22 14:32:38 +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.11 s2details
#5ACCEPTED0.11 s2details
#60.09 s2details
#70.01 s1, 2details
#80.10 s2details
#9ACCEPTED0.09 s2details
#100.01 s1, 2details
#110.10 s2details
#12ACCEPTED0.01 s1, 2details
#13ACCEPTED0.10 s2details
#14ACCEPTED0.01 s1, 2details
#15ACCEPTED0.10 s2details
#16ACCEPTED0.01 s2details
#17ACCEPTED0.01 s2details

Code

#include <bits/stdc++.h>

using namespace std;

const int N = 1002;
const int inf = 1e9;

int n,m;
int r = inf;
int v[N][N];

void f(int x, int y)
{
    if(v[x][y] != 1) return;
    v[x][y] = 2;
    f(x+1, y);
    f(x, y+1);
    f(x-1, y);
    f(x, y-1);
}

void fr(int x, int y)
{
    queue<pair<pair<int,int>,int>> q;
    q.push({{x,y},0});
    while(!q.empty())
    {
        auto e = q.front(); q.pop();
        int x = e.first.first;
        int y = e.first.second;
        int dist = e.second;
        if(x<=0 || y<=0 || x>n || y>m) continue;
        if(dist > 0 || v[x][y] == 0)
        {
            dist++;
            if(v[x][y] == 0)
            {
                v[x][y] = 3;
                q.push({{x+1, y}, dist});
                q.push({{x, y+1}, dist});
                q.push({{x-1, y}, dist});
                q.push({{x, y-1}, dist});
            }
            else if(v[x][y] == 2)
            {
                r = min(r, dist);
            }
        }
        else if(v[x][y] == 1)
        {
            v[x][y] = 3;
            q.push({{x+1, y}, 0});
            q.push({{x, y+1}, 0});
            q.push({{x-1, y}, 0});
            q.push({{x, y-1}, 0});
        }
    }
}

int main()
{
    cin>>n>>m;
    char c;
    pair<int,int> kv;
    pair<int,int> jt;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>c;
            v[i][j] = (c != '#' ? 1 : 0);
            if(c == 'A') kv = {i,j};
            if(c == 'B') jt = {i,j};
        }
    }
    f(kv.first, kv.second);
    fr(jt.first, jt.second);
    if(r == inf) r = 1;
    cout<<r;
}

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
15

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
668

Test 7

Group: 1, 2

Verdict:

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

correct output
10

user output
11

Test 8

Group: 2

Verdict:

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

correct output
436

user output
518

Test 9

Group: 2

Verdict: ACCEPTED

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

correct output
2

user output
2

Test 10

Group: 1, 2

Verdict:

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

correct output
2

user output
5

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