Task: | Sokkelo |
Sender: | Juho |
Submission time: | 2022-01-22 16:32:31 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 28 |
#2 | ACCEPTED | 72 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | ACCEPTED | 0.01 s | 1, 2 | details |
#3 | ACCEPTED | 0.01 s | 1, 2 | details |
#4 | ACCEPTED | 0.15 s | 2 | details |
#5 | ACCEPTED | 0.11 s | 2 | details |
#6 | ACCEPTED | 0.10 s | 2 | details |
#7 | ACCEPTED | 0.01 s | 1, 2 | details |
#8 | ACCEPTED | 0.08 s | 2 | details |
#9 | ACCEPTED | 0.08 s | 2 | details |
#10 | ACCEPTED | 0.01 s | 1, 2 | details |
#11 | ACCEPTED | 0.09 s | 2 | details |
#12 | ACCEPTED | 0.01 s | 1, 2 | details |
#13 | ACCEPTED | 0.07 s | 2 | details |
#14 | ACCEPTED | 0.01 s | 1, 2 | details |
#15 | ACCEPTED | 0.07 s | 2 | details |
#16 | ACCEPTED | 0.03 s | 2 | details |
#17 | ACCEPTED | 0.03 s | 2 | details |
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 |