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

Code

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

int n, m, ai, aj, bi, bj, vastaus;
int e[1000][1000];
bool t[1000][1000], seina[1000][1000];
queue<pair<int, int>> qa, qb;
char merkki;
pair<int,int> s;

void hakua(int aa, int bb) {
    if(aa<0) return;
    if(bb<0) return;
    if(aa>=n) return;
    if(bb>=m) return;
    if (t[aa][bb]) return;
    if(seina[aa][bb]) return;
    t[aa][bb]=true;
    qa.push({aa, bb});
    hakua(aa-1,bb);
    hakua(aa+1,bb);
    hakua(aa,bb-1);
    hakua(aa,bb+1);
}
void hakub(int aa, int bb) {
    if(aa<0) return;
    if(bb<0) return;
    if(aa>=n) return;
    if(bb>=m) return;
    if (t[aa][bb]) return;
    if(seina[aa][bb]) return;
    t[aa][bb]=true;
    qb.push({aa, bb});
    hakub(aa-1,bb);
    hakub(aa+1,bb);
    hakub(aa,bb-1);
    hakub(aa,bb+1);
}

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>merkki;
            if(merkki=='#'){
                seina[i][j]=true;
            }else if(merkki=='A'){
                ai=i;
                aj=j;
            }else if(merkki =='B'){
                bi=i;
                bj=j;
            }
        }
    }
    
    hakub(bi, bj);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            t[i][j]=false;
        }
    }
    hakua(ai,aj);
    
    while (!qa.empty()) {
        s = qa.front(); qa.pop();
        
        if(s.first>0){
            if(!t[s.first-1][s.second]){
                t[s.first-1][s.second]=true;
                e[s.first-1][s.second]=e[s.first][s.second]+1;
                qa.push({s.first-1, s.second});
            }
        }
        
        if(s.first<n-1){
            if(!t[s.first+1][s.second]){
                t[s.first+1][s.second]=true;
                e[s.first+1][s.second]=e[s.first][s.second]+1;
                qa.push({s.first+1, s.second});
            }
        }
        if(s.second>0){
            if(!t[s.first][s.second-1]){
                t[s.first][s.second-1]=true;
                e[s.first][s.second-1]=e[s.first][s.second]+1;
                qa.push({s.first, s.second-1});
            }
        }
        
        if(s.first<m-1){
            if(!t[s.first][s.second+1]){
                t[s.first][s.second+1]=true;
                e[s.first][s.second+1]=e[s.first][s.second]+1;
                qa.push({s.first, s.second+1});
            }
        }
    }
    
    vastaus=10000;
    
    while(!qb.empty()){
        s = qb.front(); qb.pop();
        vastaus=min(vastaus, e[s.first][s.second]);
    }
    if(vastaus==0){
        vastaus=1;
    }
    cout<<vastaus;
}

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: ACCEPTED

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

correct output
9

user output
9

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: ACCEPTED

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

correct output
335

user output
335

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: ACCEPTED

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

correct output
2

user output
2

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