結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー tailstails
提出日時 2021-07-11 02:28:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,100 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 30,700 KB
実行使用メモリ 7,576 KB
最終ジャッジ日時 2023-09-14 20:03:27
合計ジャッジ時間 1,738 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,524 KB
testcase_01 AC 7 ms
4,584 KB
testcase_02 AC 17 ms
7,524 KB
testcase_03 AC 16 ms
7,484 KB
testcase_04 AC 17 ms
7,440 KB
testcase_05 AC 17 ms
7,576 KB
testcase_06 AC 17 ms
7,492 KB
testcase_07 AC 17 ms
7,416 KB
testcase_08 AC 16 ms
7,416 KB
testcase_09 AC 16 ms
7,488 KB
testcase_10 AC 17 ms
7,476 KB
testcase_11 AC 12 ms
7,256 KB
testcase_12 AC 12 ms
7,316 KB
testcase_13 AC 12 ms
7,208 KB
testcase_14 AC 7 ms
4,664 KB
testcase_15 AC 7 ms
4,520 KB
testcase_16 AC 7 ms
4,528 KB
testcase_17 AC 7 ms
4,696 KB
testcase_18 AC 7 ms
4,576 KB
testcase_19 AC 7 ms
4,568 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:50:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   50 | main(){
      | ^~~~
main.c: 関数 ‘main’ 内:
main.c:71:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   71 |         write(1,wp,wbuf+sizeof wbuf-wp);
      |         ^~~~~
main.c:72:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   72 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

char*mmap();
#define rd_skip() while(*rp++>=48)
#define rd(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define wt(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);}
#define rep(v,e) for(long v=0;v<e;++v)

#define MD 1000000007

#define M 400001
int fac[M],ifac[M];

int inverse(int a){
	int b=MD;
	int u=1;
	int v=0;
	int s,t;
	while(b){
		t=a/b;
		s=b; b=a-t*b; a=s;
		s=v; v=u-t*v; u=s;
	}
	if(u<0){
		u+=MD;
	}
	return u;
}

void mkfac(){
	long x=1;
	fac[0]=x;
	for(long i=1;i<M;i++){
		x=x*i%MD;
		fac[i]=x;
	}
	x=inverse(x);
	for(long i=M;i--;){
		ifac[i]=x;
		x=x*i%MD;
	}
}

static inline
long f(long a,long b){
	return (long)fac[a+b]*(long)ifac[a]%MD*(long)ifac[b]%MD;
}

main(){
	mkfac();
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd(n);
	rd_skip();
	long r=0;
	while(*rp){
		long t=*rp;
		rp+=2;
		rd(x);
		rd(y);
		if(t&1){
			r+=f(x,y)*f(n-x-1,n-y)%MD;
		}else{
			r+=f(x,y)*f(n-x,n-y-1)%MD;
		}
	}
	r=(f(n,n)*n*2-r)%MD;
	r+=r<0?MD:0;
	char wbuf[64],*wp=wbuf+sizeof wbuf;
	wt(r);
	write(1,wp,wbuf+sizeof wbuf-wp);
	_exit(0);
}
0