| Task: | Island |
| Sender: | Diego_09 |
| Submission time: | 2026-04-16 11:48:19 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 0 |
| subtask | verdict | score |
|---|---|---|
| #1 | RUNTIME ERROR | 0 |
| #2 | RUNTIME ERROR | 0 |
| #3 | RUNTIME ERROR | 0 |
| #4 | RUNTIME ERROR | 0 |
| #5 | RUNTIME ERROR | 0 |
| test | verdict | time | subtask | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.03 s | 1, 5 | details |
| #2 | RUNTIME ERROR | 0.01 s | 1, 2, 3, 4, 5 | details |
| #3 | ACCEPTED | 1.31 s | 1, 5 | details |
| #4 | ACCEPTED | 1.35 s | 1, 5 | details |
| #5 | WRONG ANSWER | 0.01 s | 1, 3, 5 | details |
| #6 | ACCEPTED | 1.25 s | 1, 2, 4, 5 | details |
| #7 | ACCEPTED | 1.25 s | 1, 2, 4, 5 | details |
| #8 | ACCEPTED | 1.35 s | 1, 5 | details |
| #9 | ACCEPTED | 1.35 s | 1, 5 | details |
| #10 | ACCEPTED | 0.01 s | 1, 3, 4, 5 | details |
| #11 | ACCEPTED | 0.01 s | 1, 3, 5 | details |
| #12 | ACCEPTED | 1.29 s | 1, 4, 5 | details |
| #13 | ACCEPTED | 0.01 s | 1, 3, 4, 5 | details |
| #14 | ACCEPTED | 1.27 s | 1, 4, 5 | details |
| #15 | ACCEPTED | 1.28 s | 1, 5 | details |
| #16 | ACCEPTED | 1.32 s | 1, 5 | details |
| #17 | ACCEPTED | 1.33 s | 1, 5 | details |
| #18 | ACCEPTED | 1.36 s | 1, 5 | details |
| #19 | WRONG ANSWER | 0.07 s | 2, 4, 5 | details |
| #20 | WRONG ANSWER | 0.07 s | 2, 4, 5 | details |
| #21 | WRONG ANSWER | 0.07 s | 2, 4, 5 | details |
| #22 | WRONG ANSWER | 0.07 s | 2, 4, 5 | details |
| #23 | WRONG ANSWER | 0.10 s | 3, 5 | details |
| #24 | WRONG ANSWER | 0.10 s | 3, 5 | details |
| #25 | WRONG ANSWER | 0.10 s | 3, 5 | details |
| #26 | ACCEPTED | 0.08 s | 3, 5 | details |
| #27 | ACCEPTED | 0.07 s | 3, 4, 5 | details |
| #28 | ACCEPTED | 0.07 s | 3, 4, 5 | details |
| #29 | WRONG ANSWER | 0.07 s | 4, 5 | details |
| #30 | WRONG ANSWER | 0.07 s | 4, 5 | details |
| #31 | WRONG ANSWER | 0.07 s | 4, 5 | details |
| #32 | WRONG ANSWER | 0.07 s | 4, 5 | details |
| #33 | WRONG ANSWER | 0.07 s | 4, 5 | details |
| #34 | WRONG ANSWER | 0.07 s | 4, 5 | details |
| #35 | WRONG ANSWER | 0.07 s | 5 | details |
| #36 | WRONG ANSWER | 0.07 s | 5 | details |
| #37 | WRONG ANSWER | 0.07 s | 5 | details |
| #38 | WRONG ANSWER | 0.08 s | 5 | details |
| #39 | WRONG ANSWER | 0.07 s | 5 | details |
| #40 | WRONG ANSWER | 0.08 s | 5 | details |
| #41 | WRONG ANSWER | 0.07 s | 5 | details |
| #42 | WRONG ANSWER | 0.07 s | 5 | details |
| #43 | WRONG ANSWER | 0.07 s | 5 | details |
| #44 | WRONG ANSWER | 0.08 s | 5 | details |
Compiler report
input/code.cpp: In function 'void set_io(std::string)':
input/code.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp: In function 'void solve()':
input/code.cpp:135:22: warning: 'ix' may be used uninitialized [-Wmaybe-uninitialized]
135 | if(c22==0)bfspalo(ix,iy);
| ~~~~~~~^~~~~~~
input/code.cpp:107:9: note: 'ix' was declared here
107 | int ix,iy,c22=0;
| ^~
input/code.cpp:135:22: warning: 'iy' may be used uninitialized [-Wmaybe-u...Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#if defined(__has_include)&&__has_include("custom_h/debugging.h")
#define local_run 1
#include "custom_h\debugging.h"
#else
#define local_run 0
#endif
// #pragma GCC target ("avx2");
// #pragma GCC optimize ("Ofast");
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()
#define keyval find_by_order
#define valkey order_of_key
#define int long long
#define pb push_back
#define s second
#define f first
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
using omset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
void set_io(string name=""){
ios_base::sync_with_stdio(0);cin.tie(0);
if(name.size() and !local_run){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
}
const int mx[]={1,-1,0,0,1,-1,-1,1};
const int my[]={0,0,1,-1,1,1,-1,-1};
const int md=1e9+7;
const int oo=1e18;
vector<string>mat;
vector<vector<int>>dpalo(1001,vector<int>(1001,0));
int bfs(int x,int y,int a,int b){
vector<vector<int>>dist(1001,vector<int>(1001,oo));
queue<pair<int,int>>q;
q.push({x,y});
dist[x][y]=0;
while(!q.empty()){
x=q.front().f;
y=q.front().s;
q.pop();
// cerr<<x<<" "<<y<<"\n";
for(int i=0;i<4;i++){
int nx=x+mx[i];
int ny=y+my[i];
if(mat[nx][ny]=='#' and dist[nx][ny]==oo){
dist[nx][ny]=dist[x][y]+1;
if(nx==a and ny==b)return dist[nx][ny];
q.push({nx,ny});
}
}
}
return 0;
}
void bfspalo(int x,int y){
queue<pair<int,int>>q;
q.push({x,y});
dpalo[x][y]=1;
int cont=2;
while(!q.empty()){
x=q.front().f;
y=q.front().s;
q.pop();
for(int i=0;i<4;i++){
int nx=x+mx[i];
int ny=y+my[i];
if(mat[nx][ny]=='#' and dpalo[nx][ny]==0){
dpalo[nx][ny]=cont++;
q.push({nx,ny});
}
}
}
}
void solve(){
int n,q;
cin>>n>>q;
mat.resize(n);
for(int i=0;i<n;i++){
cin>>mat[i];
}
int ix,iy,c22=0;
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1;j++){
int c=0;
c+=mat[i][j]=='#';
c+=mat[i+1][j]=='#';
c+=mat[i][j+1]=='#';
c+=mat[i+1][j+1]=='#';
if(c==4)c22++;
int aux=0;
if(mat[i][j]=='#'){
for(int h=0;h<4;h++){
int ni=i+mx[h];
int nj=j+my[h];
if(mat[ni][nj]=='#')aux++;
}
if(aux==1){
ix=i;
iy=j;
}
}
}
}
if(c22==0)bfspalo(ix,iy);
while(q--){
int x,y,a,b;
cin>>x>>y>>a>>b;
x--;y--;a--;b--;
if(c22==0){
cout<<abs(dpalo[x][y]-dpalo[a][b])<<"\n";
continue;
}
if(n<=200 and q<=200){
cout<<bfs(x,y,a,b)<<"\n";
continue;
}
cout<<abs(x-a)<<" "<<abs(y-b)<<"\n";
}
}
int32_t main(){set_io("");
int t=1;
// cin>>t;
while(t--){
solve();
}
}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: RUNTIME ERROR
| input |
|---|
| 3 1 ... .#. ... 2 2 2 2 |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
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: WRONG ANSWER
| input |
|---|
| 200 200 ................................. |
| correct output |
|---|
| 381 544 94 532 98 ... |
| user output |
|---|
| 12837 14989 509 11444 4480 ... |
Feedback: Incorrect character on line 1 col 1: expected "381", got "12837"
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: WRONG ANSWER
| input |
|---|
| 997 100000 ................................. |
| correct output |
|---|
| 150 531 370 518 508 ... |
| user output |
|---|
| 115 35 148 383 131 239 188 330 269 239 ... |
Feedback: Output is longer than expected
Test 20
Subtask: 2, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 390 278 783 1269 249 ... |
| user output |
|---|
| 371 19 122 156 357 426 535 734 24 225 ... |
Feedback: Output is longer than expected
Test 21
Subtask: 2, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 63 142 813 683 731 ... |
| user output |
|---|
| 35 28 46 96 500 313 356 327 584 147 ... |
Feedback: Output is longer than expected
Test 22
Subtask: 2, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 949 876 1209 494 1033 ... |
| user output |
|---|
| 278 671 579 297 499 710 352 142 243 790 ... |
Feedback: Output is longer than expected
Test 23
Subtask: 3, 5
Verdict: WRONG ANSWER
| input |
|---|
| 997 100000 ................................. |
| correct output |
|---|
| 714 2683 3699 2085 7850 ... |
| user output |
|---|
| 41651 99846 75364 142222 423342 ... |
Feedback: Incorrect character on line 1 col 1: expected "714", got "41651"
Test 24
Subtask: 3, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 5081 1819 1050 4610 528 ... |
| user output |
|---|
| 238319 152440 167795 413342 63580 ... |
Feedback: Incorrect character on line 1 col 1: expected "5081", got "238319"
Test 25
Subtask: 3, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 3554 6322 6648 2882 1490 ... |
| user output |
|---|
| 207744 318658 336315 117141 17979 ... |
Feedback: Incorrect character on line 1 col 1: expected "3554", got "207744"
Test 26
Subtask: 3, 5
Verdict: ACCEPTED
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 433976 81646 87810 48080 110879 ... |
| user output |
|---|
| 433976 81646 87810 48080 110879 ... |
Test 27
Subtask: 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 207982 140036 208364 51912 56826 ... |
| user output |
|---|
| 207982 140036 208364 51912 56826 ... |
Test 28
Subtask: 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 497525 497563 498000 496804 497335 ... |
| user output |
|---|
| 497525 497563 498000 496804 497335 ... |
Test 29
Subtask: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 38580 2097 9795 38033 1639 ... |
| user output |
|---|
| 790 6 30 575 250 289 782 439 19 628 ... |
Feedback: Output is longer than expected
Test 30
Subtask: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 33 20900 25028 1782 13599 ... |
| user output |
|---|
| 1 32 392 56 482 388 49 447 256 385 ... |
Feedback: Output is longer than expected
Test 31
Subtask: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 1421 1122 1840 834 443 ... |
| user output |
|---|
| 532 83 664 458 256 164 101 229 210 233 ... |
Feedback: Output is longer than expected
Test 32
Subtask: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 1378 1751 2274 250 811 ... |
| user output |
|---|
| 486 892 690 207 723 123 29 221 154 657 ... |
Feedback: Output is longer than expected
Test 33
Subtask: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 1126 886 544 223 272 ... |
| user output |
|---|
| 714 234 323 563 392 152 17 206 49 223 ... |
Feedback: Output is longer than expected
Test 34
Subtask: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 327286 447779 447534 448307 446997 ... |
| user output |
|---|
| 728 156 996 89 996 156 996 617 996 693 ... |
Feedback: Output is longer than expected
Test 35
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 2597 1473 1933 2691 1837 ... |
| user output |
|---|
| 250 643 484 45 189 292 814 107 142 581 ... |
Feedback: Output is longer than expected
Test 36
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 553 4357 3147 6951 1573 ... |
| user output |
|---|
| 229 8 34 717 282 529 832 333 1 450 ... |
Feedback: Output is longer than expected
Test 37
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 1723 2039 1871 5638 4256 ... |
| user output |
|---|
| 137 116 621 918 210 509 135 229 327 385 ... |
Feedback: Output is longer than expected
Test 38
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 1546 704 2796 3802 1870 ... |
| user output |
|---|
| 707 225 210 156 196 190 554 374 139 193 ... |
Feedback: Output is longer than expected
Test 39
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 3115 2042 2083 3227 740 ... |
| user output |
|---|
| 388 891 12 92 315 276 811 536 137 93 ... |
Feedback: Output is longer than expected
Test 40
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 5222 3211 5230 1772 2310 ... |
| user output |
|---|
| 690 178 329 558 357 153 147 105 228 180 ... |
Feedback: Output is longer than expected
Test 41
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 159214 68851 200821 141404 145704 ... |
| user output |
|---|
| 466 594 454 259 261 746 134 526 681 539 ... |
Feedback: Output is longer than expected
Test 42
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 1843 25028 124430 84542 131339 ... |
| user output |
|---|
| 106 7 237 117 74 566 318 384 187 598 ... |
Feedback: Output is longer than expected
Test 43
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 111206 75799 12026 142133 20483 ... |
| user output |
|---|
| 376 600 71 410 301 67 71 768 114 107 ... |
Feedback: Output is longer than expected
Test 44
Subtask: 5
Verdict: WRONG ANSWER
| input |
|---|
| 1000 100000 ................................. |
| correct output |
|---|
| 20360 9075 12187 54923 54574 ... |
| user output |
|---|
| 115 195 64 85 183 118 566 543 286 536 ... |
Feedback: Output is longer than expected
