Submission details
Task:Island
Sender:AKurlavicius
Submission time:2026-04-16 12:41:31 +0300
Language:C++ (C++20)
Status:READY
Result:0
Feedback
subtaskverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimesubtask
#10.00 s1, 5details
#2ACCEPTED0.00 s1, 2, 3, 4, 5details
#30.01 s1, 5details
#40.01 s1, 5details
#50.01 s1, 3, 5details
#60.01 s1, 2, 4, 5details
#70.01 s1, 2, 4, 5details
#80.01 s1, 5details
#90.01 s1, 5details
#100.01 s1, 3, 4, 5details
#110.01 s1, 3, 5details
#120.01 s1, 4, 5details
#130.01 s1, 3, 4, 5details
#140.01 s1, 4, 5details
#150.01 s1, 5details
#160.01 s1, 5details
#170.01 s1, 5details
#180.01 s1, 5details
#190.34 s2, 4, 5details
#200.33 s2, 4, 5details
#210.34 s2, 4, 5details
#220.34 s2, 4, 5details
#230.36 s3, 5details
#240.37 s3, 5details
#250.37 s3, 5details
#260.37 s3, 5details
#270.36 s3, 4, 5details
#280.41 s3, 4, 5details
#290.36 s4, 5details
#300.36 s4, 5details
#310.35 s4, 5details
#320.41 s4, 5details
#330.34 s4, 5details
#340.41 s4, 5details
#350.38 s5details
#360.39 s5details
#370.37 s5details
#380.37 s5details
#390.37 s5details
#400.39 s5details
#410.36 s5details
#420.38 s5details
#430.38 s5details
#440.37 s5details

Code

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

int main()
{
    int n, q;
    cin>>n>>q;
    vector<int> k, d;
    for (int i=1; i<=n; i++)
    {
        char pirm='.', dab;
        for (int j=1; j<=n; j++)
        {
            cin>>dab;
            if (dab=='#' && pirm=='.')
                k.push_back(j);
            else if (dab=='.' && pirm=='#')
                d.push_back(j-1);
            pirm=dab;
        }
    }
    while (q--)
    {
        int r1, c1, r2, c2;
        cin>>r1>>c1>>r2>>c2;
        if (r1==r2)
        {
            cout<<abs(c1-c2)<<'\n';
            continue;
        }
        if (r1>r2)
        {
            swap(r1, r2);
            swap(c1, c2);
        }
        int ans=r2-r1;
        while (r1!=r2)
        {
            if (c1>d[r1+1])
            {
                ans+=c1-d[r1+1];
                c1=d[r1+1];
            }
            else if (c1<k[r1+1])
            {
                ans+=k[r1+1]-c1;
                c1=k[r1+1];
            }
            r1++;
        }
        ans+=abs(c1-c2);
        cout<<ans<<'\n';
    }
}

Test details

Test 1

Subtask: 1, 5

Verdict:

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

correct output
5
0
17
3

user output
5
0
13
9

Feedback: Incorrect character on line 3 col 2: expected "17", got "13"

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:

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

correct output
468
605
825
532
496
...

user output
744
603
1183
1518
950
...

Feedback: Incorrect character on line 1 col 1: expected "468", got "744"

Test 4

Subtask: 1, 5

Verdict:

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

correct output
112
347
142
459
239
...

user output
870
953
906
707
1303
...

Feedback: Incorrect character on line 1 col 1: expected "112", got "870"

Test 5

Subtask: 1, 3, 5

Verdict:

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

correct output
381
544
94
532
98
...

user output
927
1450
432
560
456
...

Feedback: Incorrect character on line 1 col 1: expected "381", got "927"

Test 6

Subtask: 1, 2, 4, 5

Verdict:

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

correct output
133
73
81
82
53
...

user output
133
73
81
82
53
...

Feedback: Incorrect character on line 12 col 2: expected "154", got "160"

Test 7

Subtask: 1, 2, 4, 5

Verdict:

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

correct output
139
52
101
14
144
...

user output
139
52
101
14
144
...

Feedback: Incorrect character on line 107 col 3: expected "160", got "166"

Test 8

Subtask: 1, 5

Verdict:

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

correct output
236
555
878
632
829
...

user output
626
475
376
1012
481
...

Feedback: Incorrect character on line 1 col 1: expected "236", got "626"

Test 9

Subtask: 1, 5

Verdict:

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

correct output
425
296
698
577
422
...

user output
633
532
272
427
1286
...

Feedback: Incorrect character on line 1 col 1: expected "425", got "633"

Test 10

Subtask: 1, 3, 4, 5

Verdict:

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

correct output
1365
7284
11808
6136
9283
...

user output
1421
7442
11674
6202
9423
...

Feedback: Incorrect character on line 1 col 2: expected "1365", got "1421"

Test 11

Subtask: 1, 3, 5

Verdict:

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

correct output
6292
17954
16728
8938
1335
...

user output
816
1674
3582
4350
2361
...

Feedback: Incorrect character on line 1 col 1: expected "6292", got "816"

Test 12

Subtask: 1, 4, 5

Verdict:

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

correct output
27
141
269
127
61
...

user output
27
141
269
127
61
...

Feedback: Incorrect character on line 75 col 1: expected "70", got "6"

Test 13

Subtask: 1, 3, 4, 5

Verdict:

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

correct output
19552
19544
19478
19402
19456
...

user output
19724
19754
19672
19738
19552
...

Feedback: Incorrect character on line 1 col 3: expected "19552", got "19724"

Test 14

Subtask: 1, 4, 5

Verdict:

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

correct output
17624
17515
17468
17689
17510
...

user output
17852
17911
17844
17735
17898
...

Feedback: Incorrect character on line 1 col 3: expected "17624", got "17852"

Test 15

Subtask: 1, 5

Verdict:

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

correct output
1584
1433
567
2248
1030
...

user output
954
1039
951
162
638
...

Feedback: Incorrect character on line 1 col 1: expected "1584", got "954"

Test 16

Subtask: 1, 5

Verdict:

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

correct output
5872
6374
60
323
5311
...

user output
554
1728
426
857
287
...

Feedback: Incorrect character on line 1 col 2: expected "5872", got "554"

Test 17

Subtask: 1, 5

Verdict:

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

correct output
1852
213
252
3861
1835
...

user output
668
1531
1362
537
1031
...

Feedback: Incorrect character on line 1 col 1: expected "1852", got "668"

Test 18

Subtask: 1, 5

Verdict:

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

correct output
1564
2709
866
1318
1758
...

user output
514
1867
1268
2126
2112
...

Feedback: Incorrect character on line 1 col 1: expected "1564", got "514"

Test 19

Subtask: 2, 4, 5

Verdict:

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

correct output
150
531
370
518
508
...

user output
150
531
370
518
508
...

Feedback: Incorrect character on line 239 col 2: expected "1084", got "1122"

Test 20

Subtask: 2, 4, 5

Verdict:

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

correct output
390
278
783
1269
249
...

user output
390
278
783
1269
249
...

Feedback: Incorrect character on line 1397 col 3: expected "472", got "474"

Test 21

Subtask: 2, 4, 5

Verdict:

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

correct output
63
142
813
683
731
...

user output
63
142
813
683
731
...

Feedback: Incorrect character on line 287 col 2: expected "857", got "875"

Test 22

Subtask: 2, 4, 5

Verdict:

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

correct output
949
876
1209
494
1033
...

user output
949
876
1209
494
1033
...

Feedback: Incorrect character on line 141 col 1: expected "812", got "1970"

Test 23

Subtask: 3, 5

Verdict:

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

correct output
714
2683
3699
2085
7850
...

user output
866
1863
4761
969
244
...

Feedback: Incorrect character on line 1 col 1: expected "714", got "866"

Test 24

Subtask: 3, 5

Verdict:

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

correct output
5081
1819
1050
4610
528
...

user output
1433
5753
3858
876
1308
...

Feedback: Incorrect character on line 1 col 1: expected "5081", got "1433"

Test 25

Subtask: 3, 5

Verdict:

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

correct output
3554
6322
6648
2882
1490
...

user output
5182
2668
682
1562
2284
...

Feedback: Incorrect character on line 1 col 1: expected "3554", got "5182"

Test 26

Subtask: 3, 5

Verdict:

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

correct output
433976
81646
87810
48080
110879
...

user output
23984
73430
32854
4886
23767
...

Feedback: Incorrect character on line 1 col 1: expected "433976", got "23984"

Test 27

Subtask: 3, 4, 5

Verdict:

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

correct output
207982
140036
208364
51912
56826
...

user output
209600
139684
207220
51984
57060
...

Feedback: Incorrect character on line 1 col 3: expected "207982", got "209600"

Test 28

Subtask: 3, 4, 5

Verdict:

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

correct output
497525
497563
498000
496804
497335
...

user output
498335
498757
498974
498404
499207
...

Feedback: Incorrect character on line 1 col 3: expected "497525", got "498335"

Test 29

Subtask: 4, 5

Verdict:

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

correct output
38580
2097
9795
38033
1639
...

user output
38774
2097
9795
38033
1639
...

Feedback: Incorrect character on line 1 col 3: expected "38580", got "38774"

Test 30

Subtask: 4, 5

Verdict:

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

correct output
33
20900
25028
1782
13599
...

user output
33
21192
24652
1782
13599
...

Feedback: Incorrect character on line 2 col 2: expected "20900", got "21192"

Test 31

Subtask: 4, 5

Verdict:

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

correct output
1421
1122
1840
834
443
...

user output
1421
1122
1840
834
443
...

Feedback: Incorrect character on line 33 col 1: expected "1135", got "2627"

Test 32

Subtask: 4, 5

Verdict:

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

correct output
1378
1751
2274
250
811
...

user output
1378
1751
2274
250
811
...

Feedback: Incorrect character on line 193 col 1: expected "902", got "1118"

Test 33

Subtask: 4, 5

Verdict:

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

correct output
1126
886
544
223
272
...

user output
1126
886
544
223
272
...

Feedback: Incorrect character on line 18 col 1: expected "701", got "879"

Test 34

Subtask: 4, 5

Verdict:

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

correct output
327286
447779
447534
448307
446997
...

user output
327504
449567
449294
448719
448963
...

Feedback: Incorrect character on line 1 col 4: expected "327286", got "327504"

Test 35

Subtask: 5

Verdict:

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

correct output
2597
1473
1933
2691
1837
...

user output
4869
4753
2749
8645
1989
...

Feedback: Incorrect character on line 1 col 1: expected "2597", got "4869"

Test 36

Subtask: 5

Verdict:

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

correct output
553
4357
3147
6951
1573
...

user output
2393
1415
3721
9281
451
...

Feedback: Incorrect character on line 1 col 1: expected "553", got "2393"

Test 37

Subtask: 5

Verdict:

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

correct output
1723
2039
1871
5638
4256
...

user output
1429
7207
2935
1240
4204
...

Feedback: Incorrect character on line 1 col 2: expected "1723", got "1429"

Test 38

Subtask: 5

Verdict:

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

correct output
1546
704
2796
3802
1870
...

user output
6940
2702
2464
5224
1110
...

Feedback: Incorrect character on line 1 col 1: expected "1546", got "6940"

Test 39

Subtask: 5

Verdict:

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

correct output
3115
2042
2083
3227
740
...

user output
6313
858
4569
11693
3146
...

Feedback: Incorrect character on line 1 col 1: expected "3115", got "6313"

Test 40

Subtask: 5

Verdict:

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

correct output
5222
3211
5230
1772
2310
...

user output
9230
5719
5030
2112
4358
...

Feedback: Incorrect character on line 1 col 1: expected "5222", got "9230"

Test 41

Subtask: 5

Verdict:

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

correct output
159214
68851
200821
141404
145704
...

user output
5276
5119
2995
1920
7478
...

Feedback: Incorrect character on line 1 col 1: expected "159214", got "5276"

Test 42

Subtask: 5

Verdict:

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

correct output
1843
25028
124430
84542
131339
...

user output
2933
3250
1748
3878
2585
...

Feedback: Incorrect character on line 1 col 1: expected "1843", got "2933"

Test 43

Subtask: 5

Verdict:

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

correct output
111206
75799
12026
142133
20483
...

user output
4948
1349
5332
2827
2945
...

Feedback: Incorrect character on line 1 col 1: expected "111206", got "4948"

Test 44

Subtask: 5

Verdict:

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

correct output
20360
9075
12187
54923
54574
...

user output
1622
1557
3725
7921
4778
...

Feedback: Incorrect character on line 1 col 1: expected "20360", got "1622"