結果

問題 No.2675 KUMA
ユーザー tailstails
提出日時 2024-03-18 17:23:23
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,403 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 27,392 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-18 17:23:25
合計ジャッジ時間 1,914 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 8 ms
6,676 KB
testcase_06 AC 7 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 8 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 10 ms
6,676 KB
testcase_11 AC 10 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 12 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 1 ms
6,676 KB
testcase_34 AC 1 ms
6,676 KB
testcase_35 AC 1 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 3 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 4 ms
6,676 KB
testcase_42 AC 3 ms
6,676 KB
testcase_43 AC 3 ms
6,676 KB
testcase_44 AC 4 ms
6,676 KB
testcase_45 AC 5 ms
6,676 KB
testcase_46 AC 5 ms
6,676 KB
testcase_47 AC 6 ms
6,676 KB
testcase_48 AC 9 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘f3’:
main.c:78:25: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
   78 |                         write(1,buf,1);
      |                         ^~~~~
main.c: In function ‘main’:
main.c:95:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
   95 |         _exit(0);
      |         ^~~~~
main.c:95:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define rep(v,e) for(typeof(e) v=0;v<e;++v)
#define rept(v,e,t) for(typeof(e) v=0;v<e;v+=t)

static const int d[]={1,-1,-2,-2,-1,+1,+2,+2,+1,-1};

char a[1<<16];
char b[1<<16];
int ps[1009][1009];
int kv[1005][1005];
int kxs[128],kys[128];

void f0(){
	rep(i,1<<16){
		b[i]=17;
	}
	b[0]=0;
}

void f1(int*pn,int*pkn){
	rd_init();
	int n=rd();
	int kn=0;
	rep(i,n){
		int x=rd();
		int y=rd();
		ps[y+4][x+4]=1<<i;
		rep(j,8){
			int kx=x-d[j+0];
			int ky=y-d[j+2];
			if(!kv[ky+2][kx+2]){
				kv[ky+2][kx+2]=1;
				kxs[kn]=kx;
				kys[kn]=ky;
				++kn;
			}
		}
	}
	*pn=n;
	*pkn=kn;
}

void f2(int n,int kn){
	rep(ki,kn){
		int kx=kxs[ki];
		int ky=kys[ki];
		if(!ps[ky+4][kx+4]){
			rep(i,1<<16){
				a[i]=b[i];
			}
			rept(j,8,2){
				int p=0;
				rep(c,2){
					p|=ps[ky+d[j+c+2]+4][kx+d[j+c]+4];
				}
				if(p){
					rep(i,1<<n){
						if(b[i|p]>a[i]+1){
							b[i|p]=a[i]+1;
						}
					}
				}
			}
		}
	}
}

void f3(int n){
	int z=b[(1<<n)-1];
	if(z<17){
		char buf[2];
		if(z<10){
			buf[0]=z+48;
			write(1,buf,1);
		}else{
			buf[0]=z/10+48;
			buf[1]=z%10+48;
			write(1,buf,2);
		}
	}else{
		write(1,"-1",2);
	}
}

int main(){
	f0();
	int n,kn;
	f1(&n,&kn);
	f2(n,kn);
	f3(n);
	_exit(0);
}
0