Submission details
Task:Island
Sender:jsesok
Submission time:2026-10-15 13:15:59 +0300
Language:C++ (C++23)
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.04 s1, 5details
#40.04 s1, 5details
#50.03 s1, 3, 5details
#60.03 s1, 2, 4, 5details
#70.03 s1, 2, 4, 5details
#80.03 s1, 5details
#90.04 s1, 5details
#100.03 s1, 3, 4, 5details
#110.03 s1, 3, 5details
#120.04 s1, 4, 5details
#130.03 s1, 3, 4, 5details
#140.03 s1, 4, 5details
#150.04 s1, 5details
#160.04 s1, 5details
#170.04 s1, 5details
#180.04 s1, 5details
#190.90 s2, 4, 5details
#200.83 s2, 4, 5details
#210.89 s2, 4, 5details
#221.26 s2, 4, 5details
#230.93 s3, 5details
#240.89 s3, 5details
#250.89 s3, 5details
#260.97 s3, 5details
#270.83 s3, 4, 5details
#280.79 s3, 4, 5details
#290.75 s4, 5details
#300.74 s4, 5details
#311.17 s4, 5details
#321.12 s4, 5details
#331.22 s4, 5details
#340.78 s4, 5details
#350.94 s5details
#360.97 s5details
#370.94 s5details
#380.96 s5details
#391.01 s5details
#401.02 s5details
#411.20 s5details
#421.19 s5details
#431.18 s5details
#441.12 s5details

Code

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <queue>
#include <climits>
#include <map>
#include <unordered_map>
#include <stack>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int n, q, x, y, x2, y2, sum, r, st;
    pair<int, int> s, num;
    cin>>n>>q;
    vector<vector<char>> a(n, vector<char> (n));
    for (int i=0; i<n; ++i)
    {
        for (int j=0; j<n; ++j)
        {
            cin>>a[i][j];
            if (a[i][j]=='#')
            {
                s={i, j};
            }
        }
    }
    queue<pair<int, int>> qu;
    vector<vector<int>> d(n, vector<int> (n, -1));
    vector<vector<vector<pair<int, int>>>> p(n, vector<vector<pair<int, int>>> (n, vector<pair<int, int>> (30, {-1, -1})));
    vector<vector<vector<pair<int, int>>>> g(n, vector<vector<pair<int, int>>> (n));
    for (int i=1; i<n-1; ++i)
    {
        for (int j=1; j<n-1; ++j)
        {
            if (a[i][j]=='#')
            {
                if (a[i][j+1]=='#')
                {
                    g[i][j].push_back({i, j+1});
                }
                if (a[i][j-1]=='#')
                {
                    g[i][j].push_back({i, j-1});
                }
                if (a[i+1][j]=='#')
                {
                    g[i][j].push_back({i+1, j});
                }
                if (a[i-1][j]=='#')
                {
                    g[i][j].push_back({i-1, j});
                }
            }
        }
    }
    d[s.first][s.second]=0;
    p[s.first][s.second][0]=s;
    qu.push(s);
    while (!qu.empty())
    {
        for (auto [x, y] : g[qu.front().first][qu.front().second])
        {
            if (d[x][y]==-1)
            {
                d[x][y]=d[qu.front().first][qu.front().second]+1;
                p[x][y][0]={qu.front().first, qu.front().second};
                qu.push({x, y});
            }
        }
        qu.pop();
    }
    for (int i=1; i<30; ++i)
    {
        for (int j=0; j<n; ++j)
        {
            for (int z=0; z<n; ++z)
            {
                if (a[j][z]=='#')
                {
                    p[j][z][i]=p[p[j][z][i-1].first][p[j][z][i-1].second][i-1];
                }
            }
        }
    }
    for (int i=0; i<q; ++i)
    {
        cin>>x>>y>>x2>>y2;
        x-=1;
        y-=1;
        x2-=1;
        y2-=1;
        if (d[x][y]<d[x2][y2])
        {
            swap(x, x2);
            swap(y, y2);
        }
        st=1;
        for (int j=0; j<29; ++j)
            st*=2;
        r=d[x][y]-d[x2][y2];
        sum=r;
        for (int j=29; j>=0; --j)
        {
            if (st<=r)
            {
                r-=st;
                num=p[x][y][j];
                x=num.first;
                y=num.second;
            }
        }
        st=1;
        for (int j=0; j<29; ++j)
            st*=2;
        for (int j=29; j>=0; --j)
        {
            if (p[x][y][j]!=p[x2][y2][j])
            {
                sum+=st;
                num=p[x][y][j];
                x=num.first;
                y=num.second;
                num=p[x2][y2][j];
                x2=num.first;
                y2=num.second;
            }
        }
        cout<<sum<<"\n";
    }
    return 0;
}

Test details

Test 1

Subtask: 1, 5

Verdict:

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

correct output
5
0
17
3

user output
-2147483643
0
536870929
536870915

Feedback: Incorrect character on line 1 col 1: expected "5", got "-2147483643"

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
-1073741562
-1073741371
-1610612153
-536870462
-1610612240
...

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

Test 4

Subtask: 1, 5

Verdict:

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

correct output
112
347
142
459
239
...

user output
1610612774
-2147483339
-2147483524
-2147483333
-1073741615
...

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

Test 5

Subtask: 1, 3, 5

Verdict:

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

correct output
381
544
94
532
98
...

user output
-1073741511
-1073741296
-2147483554
-2147483124
-1610612646
...

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

Test 6

Subtask: 1, 2, 4, 5

Verdict:

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

correct output
133
73
81
82
53
...

user output
-1073741691
-1610612715
-1073741743
-2147483566
-2147483605
...

Feedback: Incorrect character on line 1 col 1: expected "133", got "-1073741691"

Test 7

Subtask: 1, 2, 4, 5

Verdict:

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

correct output
139
52
101
14
144
...

user output
-1073741711
1610612782
1610612837
1610612744
-1073741680
...

Feedback: Incorrect character on line 1 col 1: expected "139", got "-1073741711"

Test 8

Subtask: 1, 5

Verdict:

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

correct output
236
555
878
632
829
...

user output
536871080
-1073741811
-2147483388
-2147483202
1610613093
...

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

Test 9

Subtask: 1, 5

Verdict:

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

correct output
425
296
698
577
422
...

user output
-1610612493
-1610612608
-2147483566
-1073741681
-536870782
...

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

Test 10

Subtask: 1, 3, 4, 5

Verdict:

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

correct output
1365
7284
11808
6136
9283
...

user output
-536869547
536878196
-536859104
536877048
1073751107
...

Feedback: Incorrect character on line 1 col 1: expected "1365", got "-536869547"

Test 11

Subtask: 1, 3, 5

Verdict:

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

correct output
6292
17954
16728
8938
1335
...

user output
-536864620
17954
-1610596008
8938
1073743159
...

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

Test 12

Subtask: 1, 4, 5

Verdict:

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

correct output
27
141
269
127
61
...

user output
-1610612719
-1610612695
-2147483541
-1610612723
1073741875
...

Feedback: Incorrect character on line 1 col 1: expected "27", got "-1610612719"

Test 13

Subtask: 1, 3, 4, 5

Verdict:

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

correct output
19552
19544
19478
19402
19456
...

user output
536890464
-1073722280
-1073722346
-536851510
-536851456
...

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

Test 14

Subtask: 1, 4, 5

Verdict:

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

correct output
17624
17515
17468
17689
17510
...

user output
-1610595112
-1610595221
-536853444
1073759513
-1073724314
...

Feedback: Incorrect character on line 1 col 1: expected "17624", got "-1610595112"

Test 15

Subtask: 1, 5

Verdict:

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

correct output
1584
1433
567
2248
1030
...

user output
-1610611170
-536869479
-1610612169
-536868664
-536869882
...

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

Test 16

Subtask: 1, 5

Verdict:

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

correct output
5872
6374
60
323
5311
...

user output
-1610606864
1073748198
-536870852
-2147483325
-1073736515
...

Feedback: Incorrect character on line 1 col 1: expected "5872", got "-1610606864"

Test 17

Subtask: 1, 5

Verdict:

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

correct output
1852
213
252
3861
1835
...

user output
-536869066
213
252
-536867055
-2147481815
...

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

Test 18

Subtask: 1, 5

Verdict:

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

correct output
1564
2709
866
1318
1758
...

user output
536872476
-536868215
-1073740958
-1073740508
1752
...

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

Test 19

Subtask: 2, 4, 5

Verdict:

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

correct output
150
531
370
518
508
...

user output
-1610612656
-1610612205
-1610612366
-536870770
-536870404
...

Feedback: Incorrect character on line 1 col 1: expected "150", got "-1610612656"

Test 20

Subtask: 2, 4, 5

Verdict:

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

correct output
390
278
783
1269
249
...

user output
-1073741460
-1610612458
1610612805
-536870757
-1610612535
...

Feedback: Incorrect character on line 1 col 1: expected "390", got "-1073741460"

Test 21

Subtask: 2, 4, 5

Verdict:

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

correct output
63
142
813
683
731
...

user output
-1610612673
-1610612594
-1073741105
-1610612239
-1610612125
...

Feedback: Incorrect character on line 1 col 1: expected "63", got "-1610612673"

Test 22

Subtask: 2, 4, 5

Verdict:

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

correct output
949
876
1209
494
1033
...

user output
-1610612343
-1073740948
-1073741613
1610613230
-536869879
...

Feedback: Incorrect character on line 1 col 1: expected "949", got "-1610612343"

Test 23

Subtask: 3, 5

Verdict:

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

correct output
714
2683
3699
2085
7850
...

user output
-1610612224
1925
-1073739727
-536868867
-1073734454
...

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

Test 24

Subtask: 3, 5

Verdict:

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

correct output
5081
1819
1050
4610
528
...

user output
-1073740009
-1610611329
-1073740778
-1073738386
-1073741384
...

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

Test 25

Subtask: 3, 5

Verdict:

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

correct output
3554
6322
6648
2882
1490
...

user output
1073745064
3926
-1610608498
-1073739964
-1610612470
...

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

Test 26

Subtask: 3, 5

Verdict:

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

correct output
433976
81646
87810
48080
110879
...

user output
-2147049672
81646
1610700546
1073789904
1610723615
...

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

Test 27

Subtask: 3, 4, 5

Verdict:

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

correct output
207982
140036
208364
51912
56826
...

user output
-2147275666
1610752772
-1073533460
1610664648
1073798650
...

Feedback: Incorrect character on line 1 col 1: expected "207982", got "-2147275666"

Test 28

Subtask: 3, 4, 5

Verdict:

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

correct output
497525
497563
498000
496804
497335
...

user output
1074239349
1074239387
-2146985648
537367716
-1610115401
...

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

Test 29

Subtask: 4, 5

Verdict:

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

correct output
38580
2097
9795
38033
1639
...

user output
-1073703298
1610614833
-1073732029
536908621
536872267
...

Feedback: Incorrect character on line 1 col 1: expected "38580", got "-1073703298"

Test 30

Subtask: 4, 5

Verdict:

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

correct output
33
20900
25028
1782
13599
...

user output
536870945
-1073720924
1610637676
-1610610984
536884069
...

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

Test 31

Subtask: 4, 5

Verdict:

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

correct output
1421
1122
1840
834
443
...

user output
-536870463
1122
536871004
-1610612406
-2147483205
...

Feedback: Incorrect character on line 1 col 1: expected "1421", got "-536870463"

Test 32

Subtask: 4, 5

Verdict:

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

correct output
1378
1751
2274
250
811
...

user output
-536870418
-1610611429
-536869656
-1073741632
1610613239
...

Feedback: Incorrect character on line 1 col 1: expected "1378", got "-536870418"

Test 33

Subtask: 4, 5

Verdict:

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

correct output
1126
886
544
223
272
...

user output
-1610612256
-1610612496
-1073741280
-1073741601
-2147483376
...

Feedback: Incorrect character on line 1 col 1: expected "1126", got "-1610612256"

Test 34

Subtask: 4, 5

Verdict:

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

correct output
327286
447779
447534
448307
446997
...

user output
1610940022
1611060515
1611060270
537319219
1611059733
...

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

Test 35

Subtask: 5

Verdict:

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

correct output
2597
1473
1933
2691
1837
...

user output
725
-2147483165
-1610610911
-1073739897
-536870309
...

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

Test 36

Subtask: 5

Verdict:

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

correct output
553
4357
3147
6951
1573
...

user output
295
-536866597
536872575
536877233
-536870401
...

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

Test 37

Subtask: 5

Verdict:

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

correct output
1723
2039
1871
5638
4256
...

user output
-536869467
-1073741355
-536869403
-2147481070
-1610612554
...

Feedback: Incorrect character on line 1 col 1: expected "1723", got "-536869467"

Test 38

Subtask: 5

Verdict:

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

correct output
1546
704
2796
3802
1870
...

user output
-1073740352
-1610612126
-1610611212
-1610611346
-1073740892
...

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

Test 39

Subtask: 5

Verdict:

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

correct output
3115
2042
2083
3227
740
...

user output
-536870397
-536870906
-1073740703
-2147483129
-1073741576
...

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

Test 40

Subtask: 5

Verdict:

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

correct output
5222
3211
5230
1772
2310
...

user output
-536865752
-536868281
-536866144
-1073740248
536872862
...

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

Test 41

Subtask: 5

Verdict:

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

correct output
159214
68851
200821
141404
145704
...

user output
-1610453656
-536802061
1073942645
-2147342244
-536725410
...

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

Test 42

Subtask: 5

Verdict:

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

correct output
1843
25028
124430
84542
131339
...

user output
536872753
-536845884
124430
536955342
-536739667
...

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

Test 43

Subtask: 5

Verdict:

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

correct output
111206
75799
12026
142133
20483
...

user output
1073852968
-536795117
536882938
1073883891
-536850431
...

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

Test 44

Subtask: 5

Verdict:

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

correct output
20360
9075
12187
54923
54574
...

user output
1073762024
-1610603661
12187
-536816181
1610667302
...

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