Submission details
Task:Island
Sender:053thousand
Submission time:2026-04-16 11:02:14 +0300
Language:C++ (C++11)
Status:READY
Result:10
Feedback
subtaskverdictscore
#1ACCEPTED10
#20
#30
#40
#50
Test results
testverdicttimesubtask
#1ACCEPTED0.01 s1, 5details
#2ACCEPTED0.01 s1, 2, 3, 4, 5details
#3ACCEPTED0.12 s1, 5details
#4ACCEPTED0.13 s1, 5details
#5ACCEPTED0.09 s1, 3, 5details
#6ACCEPTED0.06 s1, 2, 4, 5details
#7ACCEPTED0.05 s1, 2, 4, 5details
#8ACCEPTED0.12 s1, 5details
#9ACCEPTED0.12 s1, 5details
#10ACCEPTED0.05 s1, 3, 4, 5details
#11ACCEPTED0.05 s1, 3, 5details
#12ACCEPTED0.08 s1, 4, 5details
#13ACCEPTED0.09 s1, 3, 4, 5details
#14ACCEPTED0.08 s1, 4, 5details
#15ACCEPTED0.07 s1, 5details
#16ACCEPTED0.10 s1, 5details
#17ACCEPTED0.11 s1, 5details
#18ACCEPTED0.14 s1, 5details
#190.03 s2, 4, 5details
#200.03 s2, 4, 5details
#210.03 s2, 4, 5details
#220.03 s2, 4, 5details
#230.03 s3, 5details
#240.03 s3, 5details
#250.03 s3, 5details
#260.03 s3, 5details
#270.03 s3, 4, 5details
#280.03 s3, 4, 5details
#290.03 s4, 5details
#300.03 s4, 5details
#310.03 s4, 5details
#320.03 s4, 5details
#330.03 s4, 5details
#340.03 s4, 5details
#350.03 s5details
#360.03 s5details
#370.03 s5details
#380.03 s5details
#390.03 s5details
#400.03 s5details
#410.03 s5details
#420.03 s5details
#430.03 s5details
#440.04 s5details

Compiler report

input/code.cpp: In function 'int bfs(int, int, int, int)':
input/code.cpp:32:1: warning: control reaches end of non-void function [-Wreturn-type]
   32 | }
      | ^

Code

#include<bits/stdc++.h>
using namespace std;
	int a,b,c,d,e,f,g,dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
	string str[1005];
	vector<int>v[1005];
int bfs(int x,int y,int z,int aa){
	bool vis[1005][1005]={0};
	queue<pair<pair<int,int>,int>>q;
	for(int i=0;i<=a;i++){
	for(int h=0;h<=a;h++){
		vis[i][h]=0;
	}	
	}
	while(!q.empty()) q.pop();
	q.push({{x,y},0});
	vis[x][y]=1;
	while(!q.empty()){
		int q1=q.front().first.first,q2=q.front().first.second,q3=q.front().second;
//		cout<<q1<<' '<<q2<<' '<<q3<<endl;
		q.pop();
		if(q1==z and q2==aa){
			return q3;
		}
		for(int i=0;i<4;i++){
			if(vis[q1+dir[i][0]][q2+dir[i][1]]==0 and str[q1+dir[i][0]][q2+dir[i][1]]=='#'){
				vis[q1+dir[i][0]][q2+dir[i][1]]=1;
				q.push({{q1+dir[i][0],q2+dir[i][1]},q3+1});
			}
		}
	}
//	cout<<"Balls\n";
}
int main(){
	cin>>a>>b;
	for(int i=0;i<a;i++) cin>>str[i];
	if(a<=200 and b<=200){
		for(int i=0;i<b;i++){
			cin>>d>>e>>f>>g;
			cout<<bfs(d-1,e-1,f-1,g-1)<<endl;
		}
	}
	else{
		cin>>d>>e>>f>>g;
		cout<<abs(f-d)+abs(e-g);
	}
}

Test details

Test 1

Subtask: 1, 5

Verdict: ACCEPTED

input
8 4
........
..####..
.##.###.
.##.###.
...

correct output
5
0
17
3

user output
5
0
17
3

Test 2

Subtask: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
3 1
...
.#.
...
2 2 2 2

correct output
0

user output
0

Test 3

Subtask: 1, 5

Verdict: ACCEPTED

input
199 196
.................................

correct output
468
605
825
532
496
...

user output
468
605
825
532
496
...

Test 4

Subtask: 1, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
112
347
142
459
239
...

user output
112
347
142
459
239
...

Test 5

Subtask: 1, 3, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
381
544
94
532
98
...

user output
381
544
94
532
98
...

Test 6

Subtask: 1, 2, 4, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
133
73
81
82
53
...

user output
133
73
81
82
53
...

Test 7

Subtask: 1, 2, 4, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
139
52
101
14
144
...

user output
139
52
101
14
144
...

Test 8

Subtask: 1, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
236
555
878
632
829
...

user output
236
555
878
632
829
...

Test 9

Subtask: 1, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
425
296
698
577
422
...

user output
425
296
698
577
422
...

Test 10

Subtask: 1, 3, 4, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
1365
7284
11808
6136
9283
...

user output
1365
7284
11808
6136
9283
...

Test 11

Subtask: 1, 3, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
6292
17954
16728
8938
1335
...

user output
6292
17954
16728
8938
1335
...

Test 12

Subtask: 1, 4, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
27
141
269
127
61
...

user output
27
141
269
127
61
...

Test 13

Subtask: 1, 3, 4, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
19552
19544
19478
19402
19456
...

user output
19552
19544
19478
19402
19456
...

Test 14

Subtask: 1, 4, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
17624
17515
17468
17689
17510
...

user output
17624
17515
17468
17689
17510
...

Test 15

Subtask: 1, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
1584
1433
567
2248
1030
...

user output
1584
1433
567
2248
1030
...

Test 16

Subtask: 1, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
5872
6374
60
323
5311
...

user output
5872
6374
60
323
5311
...

Test 17

Subtask: 1, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
1852
213
252
3861
1835
...

user output
1852
213
252
3861
1835
...

Test 18

Subtask: 1, 5

Verdict: ACCEPTED

input
200 200
.................................

correct output
1564
2709
866
1318
1758
...

user output
1564
2709
866
1318
1758
...

Test 19

Subtask: 2, 4, 5

Verdict:

input
997 100000
.................................

correct output
150
531
370
518
508
...

user output
150

Feedback: Output is shorter than expected

Test 20

Subtask: 2, 4, 5

Verdict:

input
1000 100000
.................................

correct output
390
278
783
1269
249
...

user output
390

Feedback: Output is shorter than expected

Test 21

Subtask: 2, 4, 5

Verdict:

input
1000 100000
.................................

correct output
63
142
813
683
731
...

user output
63

Feedback: Output is shorter than expected

Test 22

Subtask: 2, 4, 5

Verdict:

input
1000 100000
.................................

correct output
949
876
1209
494
1033
...

user output
949

Feedback: Output is shorter than expected

Test 23

Subtask: 3, 5

Verdict:

input
997 100000
.................................

correct output
714
2683
3699
2085
7850
...

user output
302

Feedback: Output is shorter than expected

Test 24

Subtask: 3, 5

Verdict:

input
1000 100000
.................................

correct output
5081
1819
1050
4610
528
...

user output
53

Feedback: Output is shorter than expected

Test 25

Subtask: 3, 5

Verdict:

input
1000 100000
.................................

correct output
3554
6322
6648
2882
1490
...

user output
498

Feedback: Output is shorter than expected

Test 26

Subtask: 3, 5

Verdict:

input
1000 100000
.................................

correct output
433976
81646
87810
48080
110879
...

user output
848

Feedback: Output is shorter than expected

Test 27

Subtask: 3, 4, 5

Verdict:

input
1000 100000
.................................

correct output
207982
140036
208364
51912
56826
...

user output
528

Feedback: Output is shorter than expected

Test 28

Subtask: 3, 4, 5

Verdict:

input
1000 100000
.................................

correct output
497525
497563
498000
496804
497335
...

user output
1019

Feedback: Output is shorter than expected

Test 29

Subtask: 4, 5

Verdict:

input
1000 100000
.................................

correct output
38580
2097
9795
38033
1639
...

user output
796

Feedback: Output is shorter than expected

Test 30

Subtask: 4, 5

Verdict:

input
1000 100000
.................................

correct output
33
20900
25028
1782
13599
...

user output
33

Feedback: Output is shorter than expected

Test 31

Subtask: 4, 5

Verdict:

input
1000 100000
.................................

correct output
1421
1122
1840
834
443
...

user output
615

Feedback: Output is shorter than expected

Test 32

Subtask: 4, 5

Verdict:

input
1000 100000
.................................

correct output
1378
1751
2274
250
811
...

user output
1378

Feedback: Output is shorter than expected

Test 33

Subtask: 4, 5

Verdict:

input
1000 100000
.................................

correct output
1126
886
544
223
272
...

user output
948

Feedback: Output is shorter than expected

Test 34

Subtask: 4, 5

Verdict:

input
1000 100000
.................................

correct output
327286
447779
447534
448307
446997
...

user output
884

Feedback: Output is shorter than expected

Test 35

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
2597
1473
1933
2691
1837
...

user output
893

Feedback: Output is shorter than expected

Test 36

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
553
4357
3147
6951
1573
...

user output
237

Feedback: Output is shorter than expected

Test 37

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
1723
2039
1871
5638
4256
...

user output
253

Feedback: Output is shorter than expected

Test 38

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
1546
704
2796
3802
1870
...

user output
932

Feedback: Output is shorter than expected

Test 39

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
3115
2042
2083
3227
740
...

user output
1279

Feedback: Output is shorter than expected

Test 40

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
5222
3211
5230
1772
2310
...

user output
868

Feedback: Output is shorter than expected

Test 41

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
159214
68851
200821
141404
145704
...

user output
1060

Feedback: Output is shorter than expected

Test 42

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
1843
25028
124430
84542
131339
...

user output
113

Feedback: Output is shorter than expected

Test 43

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
111206
75799
12026
142133
20483
...

user output
976

Feedback: Output is shorter than expected

Test 44

Subtask: 5

Verdict:

input
1000 100000
.................................

correct output
20360
9075
12187
54923
54574
...

user output
310

Feedback: Output is shorter than expected