結果

問題 No.1315 渦巻洞穴
ユーザー tailstails
提出日時 2020-12-12 04:19:04
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,022 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 31,752 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 01:56:26
合計ジャッジ時間 3,396 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 4 ms
4,348 KB
testcase_47 AC 4 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 3 ms
4,348 KB
testcase_51 AC 4 ms
4,348 KB
testcase_52 AC 3 ms
4,348 KB
testcase_53 AC 3 ms
4,348 KB
testcase_54 AC 3 ms
4,348 KB
testcase_55 AC 3 ms
4,348 KB
testcase_56 AC 3 ms
4,348 KB
testcase_57 AC 3 ms
4,348 KB
testcase_58 AC 3 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
testcase_64 AC 2 ms
4,348 KB
testcase_65 AC 2 ms
4,348 KB
testcase_66 AC 2 ms
4,348 KB
testcase_67 AC 2 ms
4,348 KB
testcase_68 AC 2 ms
4,348 KB
testcase_69 AC 2 ms
4,348 KB
testcase_70 AC 2 ms
4,348 KB
testcase_71 AC 2 ms
4,348 KB
testcase_72 AC 2 ms
4,348 KB
testcase_73 AC 2 ms
4,348 KB
testcase_74 AC 2 ms
4,348 KB
testcase_75 AC 1 ms
4,348 KB
testcase_76 AC 1 ms
4,348 KB
testcase_77 AC 2 ms
4,348 KB
testcase_78 AC 2 ms
4,348 KB
testcase_79 AC 2 ms
4,348 KB
testcase_80 AC 2 ms
4,348 KB
testcase_81 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'locate':
main.c:7:20: warning: implicit declaration of function 'sqrt' [-Wimplicit-function-declaration]
    7 |         int r=(int)sqrt(s-1)+1&~1;
      |                    ^~~~
main.c:1:1: note: include '<math.h>' or provide a declaration of 'sqrt'
  +++ |+#include <math.h>
    1 | static inline
main.c:7:20: warning: incompatible implicit declaration of built-in function 'sqrt' [-Wbuiltin-declaration-mismatch]
    7 |         int r=(int)sqrt(s-1)+1&~1;
      |                    ^~~~
main.c:7:20: note: include '<math.h>' or provide a declaration of 'sqrt'
main.c: In function 'numat':
main.c:25:19: warning: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
   25 |         int r=max(abs(x),abs(y))<<1;
      |                   ^~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'abs'
  +++ |+#include <stdlib.h>
    1 | static inline
main.c: In function 'f1':
main.c:66:25: warning: implicit declaration of function 'putchar' [-Wimplicit-function-declaration]
   66 |                         putchar(c);
      |                         ^~~~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'putchar'
  +++ |+#include <stdio.h>
    1 | static inline
main.c: At top level:
main.c:82:1: warning: return type defaults to 'int' [-Wimplicit-int]
   82 | main(){
      | ^~~~
main.c: In function 'main':
main.c:84:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   84 |         scanf("%d%d",&s,&t);
      |         ^~~~~
main.c:84:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:84:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
main.c:84:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:127:9: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
  127 |         printf("0\n");
      |         ^~~~~~
main.c:127:9: note: include '<s

ソースコード

diff #

static inline
int max(int a,int b){
	return a>b?a:b;
}

void locate(int s,int*px,int*py){
	int r=(int)sqrt(s-1)+1&~1;
	int t=(r+1)*(r+1)-s;
	if(t<r){
		*px=(r>>1)-t;
		*py=(r>>1);
	}else if(t-=r,t<r){
		*px=-(r>>1);
		*py=(r>>1)-t;
	}else if(t-=r,t<r){
		*px=-(r>>1)+t;
		*py=-(r>>1);
	}else if(t-=r,1){
		*px=(r>>1);
		*py=-(r>>1)+t;
	}
}

int numat(int x,int y){
	int r=max(abs(x),abs(y))<<1;
	int t;
	if((r>>1)==y){
		t=-x;
	}else if((r>>1)==-x){
		t=r-y;
	}else if((r>>1)==-y){
		t=r*2+x;
	}else{
		t=r*3+y;
	}
	return (r+1)*(r+1)-(r>>1)-t;
}

int vvs[33];

int f1(int ox,int oy,int zx,int zy,int outq,int fv){
	while(!(ox==zx&&oy==zy)){
		int nx,ny,c,crev;
		if(ox<zx){
			nx=ox+1;
			ny=oy;
			c='R'; crev='L';
		}else if(ox>zx){
			nx=ox-1;
			ny=oy;
			c='L'; crev='R';
		}else if(oy<zy){
			nx=ox;
			ny=oy+1;
			c='D'; crev='U';
		}else{
			nx=ox;
			ny=oy-1;
			c='U'; crev='D';
		}
		int ov=numat(ox,oy);
		int nv=numat(nx,ny);
		int vv=ov^nv;
		int bw=31-__builtin_clz(vv);
		if(outq){
			putchar(c);
			if(bw>=5&&fv&1<<bw&&vv==vvs[bw]){
				putchar(crev);
				putchar(c);
				fv&=~(1<<bw);
			}
		}else{
			vvs[bw]=vv;
			fv^=nv;
		}
		ox=nx;
		oy=ny;
	}
	return fv;
}

main(){
	int s,t;
	scanf("%d%d",&s,&t);
	int sx,sy,tx,ty;
	locate(s,&sx,&sy);
	locate(t,&tx,&ty);

	int av=s;
	av=f1(sx,sy,0,0,0,av);
	av=f1(0,0,tx,ty,0,av);
	int k=abs(sx)+abs(sy)+abs(tx)+abs(ty);

	int fv=0;
	for(int iv=1<<30;iv>=32;iv>>=1){
		if(av&iv){
			fv|=iv;
			av^=vvs[31-__builtin_clz(iv)];
			k+=2;
		}
	}
	if(av&16){
		fv|=16;
		av^=19^1; // 1 -> 1,6,19,6,1
		k+=4;
	}
	if(av&8){
		fv|=8;
		av^=8^1; // 1 -> 1,8,1
		k+=2;
	}
	if(av&4){
		fv|=4;
		av^=4^1; // 1 -> 1,4,1
		k+=2;
	}
	if(av&2){
		fv|=2;
		av^=2^1; // 1 -> 1,8,1
		k+=2;
	}
	if(av&1){
		fv|=1;
		av^=1; // 1 -> 1,2,3,2,1,2,1
		k+=6;
	}
	printf("0\n");
	printf("%d\n",k);
	fv=f1(sx,sy,0,0,1,fv);
	if(fv&16) printf("LLRR");
	if(fv&8) printf("DU");
	if(fv&4) printf("UD");
	if(fv&2) printf("RL");
	if(fv&1) printf("RUDLRL");
	fv=f1(0,0,tx,ty,1,fv);
	putchar(10);
}
0