結果
問題 | No.1323 うしらずSwap |
ユーザー | tails |
提出日時 | 2020-12-20 01:58:33 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,804 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 32,256 KB |
実行使用メモリ | 272,512 KB |
最終ジャッジ日時 | 2024-09-21 11:20:41 |
合計ジャッジ時間 | 9,447 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | WA | - |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 112 ms
143,616 KB |
testcase_17 | AC | 198 ms
148,608 KB |
testcase_18 | AC | 108 ms
143,872 KB |
testcase_19 | AC | 203 ms
148,480 KB |
testcase_20 | AC | 108 ms
143,488 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 140 ms
143,616 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 317 ms
208,128 KB |
testcase_34 | AC | 305 ms
230,272 KB |
testcase_35 | AC | 297 ms
241,152 KB |
testcase_36 | AC | 281 ms
248,192 KB |
testcase_37 | AC | 278 ms
251,648 KB |
testcase_38 | AC | 332 ms
268,416 KB |
testcase_39 | AC | 288 ms
270,432 KB |
testcase_40 | AC | 303 ms
271,488 KB |
testcase_41 | AC | 296 ms
272,512 KB |
testcase_42 | AC | 277 ms
272,384 KB |
testcase_43 | AC | 72 ms
66,176 KB |
testcase_44 | AC | 118 ms
86,528 KB |
testcase_45 | AC | 104 ms
100,992 KB |
testcase_46 | AC | 125 ms
86,528 KB |
testcase_47 | AC | 78 ms
79,104 KB |
testcase_48 | AC | 69 ms
66,304 KB |
testcase_49 | AC | 119 ms
86,528 KB |
testcase_50 | AC | 62 ms
57,600 KB |
testcase_51 | AC | 33 ms
26,496 KB |
testcase_52 | AC | 43 ms
38,016 KB |
testcase_53 | AC | 118 ms
86,528 KB |
testcase_54 | AC | 46 ms
38,144 KB |
testcase_55 | AC | 114 ms
86,656 KB |
testcase_56 | AC | 32 ms
27,392 KB |
testcase_57 | AC | 140 ms
107,392 KB |
testcase_58 | AC | 1 ms
5,376 KB |
testcase_59 | AC | 13 ms
14,464 KB |
testcase_60 | AC | 1 ms
5,376 KB |
testcase_61 | AC | 1 ms
5,376 KB |
コンパイルメッセージ
main.c:7:19: warning: no semicolon at end of struct or union 7 | struct{int y,x,z,d} q[16000000]; | ^ main.c:93:1: warning: return type defaults to 'int' [-Wimplicit-int] 93 | main(){ | ^~~~ main.c: In function 'main': main.c:94:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 94 | scanf("%d%d%d%d%d%d",&h,&w,&ra,&ca,&rb,&cb); | ^~~~~ main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf' +++ |+#include <stdio.h> 1 | int h,w,ra,ca,rb,cb; main.c:94:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch] 94 | scanf("%d%d%d%d%d%d",&h,&w,&ra,&ca,&rb,&cb); | ^~~~~ main.c:94:9: note: include '<stdio.h>' or provide a declaration of 'scanf' main.c:102:17: warning: implicit declaration of function 'puts' [-Wimplicit-function-declaration] 102 | puts("-1"); | ^~~~ main.c:102:17: note: include '<stdio.h>' or provide a declaration of 'puts' main.c:103:17: warning: implicit declaration of function 'exit' [-Wimplicit-function-declaration] 103 | exit(0); | ^~~~ main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'exit' +++ |+#include <stdlib.h> 1 | int h,w,ra,ca,rb,cb; main.c:103:17: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch] 103 | exit(0); | ^~~~ main.c:103:17: note: include '<stdlib.h>' or provide a declaration of 'exit' main.c:118:17: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch] 118 | exit(0); | ^~~~ main.c:118:17: note: include '<stdlib.h>' or provide a declaration of 'exit' main.c:120:9: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 120 |
ソースコード
int h,w,ra,ca,rb,cb; char s[1333][1335]; int dp1[1333][1333]; int dp2[1333][1333][2]; struct{int y,x,z,d} q[16000000]; int qr,qw; void enq(int y,int x,int z,int d){ q[qw].y=y; q[qw].x=x; q[qw].z=z; q[qw].d=d; ++qw; } void f1(){ qr=qw=0; enq(ra,ca,0,1); while(qr<qw){ int y=q[qr].y; int x=q[qr].x; int d=q[qr].d; ++qr; if(s[y][x]=='.'&&dp1[y][x]==0){ dp1[y][x]=d; enq(y-1,x,0,d+1); enq(y+1,x,0,d+1); enq(y,x-1,0,d+1); enq(y,x+1,0,d+1); } } } void f2(int y,int x){ int d=dp1[y][x]; dp1[y][x]=-1; if(d==1){ }else if(dp1[y-1][x]==d-1){ f2(y-1,x); }else if(dp1[y+1][x]==d-1){ f2(y+1,x); }else if(dp1[y][x-1]==d-1){ f2(y,x-1); }else if(dp1[y][x+1]==d-1){ f2(y,x+1); } } void f3(){ qr=qw=0; enq(ra,ca,0,1); while(qr<qw){ int y=q[qr].y; int x=q[qr].x; int z=q[qr].z; int d=q[qr].d; ++qr; if(s[y][x]=='.'&&dp2[y][x][z]==0&&(z?!(y==ra&&x==ca):!(y==rb&&x==cb))){ dp2[y][x][z]=d; if(z==0&&dp1[y][x]>=0){ enq(y,x,1,d+1); } enq(y-1,x,z,d+1); enq(y+1,x,z,d+1); enq(y,x-1,z,d+1); enq(y,x+1,z,d+1); } } } int f4a(int r,int c){ return s[r][c]=='.'&&dp1[r][c]>=0; } int f4(int r,int c){ int d=1; while(1){ dp1[r][c]=-1; int a=f4a(r-1,c)+f4a(r+1,c)+f4a(r,c-1)+f4a(r,c+1); if(a>=2){ return d*4; } if(a==0){ return 3000000; } r+=f4a(r+1,c)-f4a(r-1,c); c+=f4a(r,c+1)-f4a(r,c-1); d+=1; } } main(){ scanf("%d%d%d%d%d%d",&h,&w,&ra,&ca,&rb,&cb); --ra;--ca;--rb;--cb; for(int y=0;y<h;++y){ scanf("%s",s[y]); } f1(); int d1=dp1[rb][cb]-1; if(d1<0){ puts("-1"); exit(0); } f2(rb,cb); f3(); int d2=dp2[rb][cb][1]-2; if(d2<0){ d2=3000000; } int d; d=f4(ra,ca)+d1; if(d2>d) d2=d; d=f4(rb,cb)+d1; if(d2>d) d2=d; if(d2==3000000){ puts("-1"); exit(0); } printf("%d",d1+d2); }