結果

問題 No.1884 Sequence
ユーザー tailstails
提出日時 2022-03-26 22:14:18
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 930 ms
コンパイル使用メモリ 30,400 KB
実行使用メモリ 7,812 KB
最終ジャッジ日時 2023-08-05 17:08:55
合計ジャッジ時間 3,683 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 0 ms
4,380 KB
testcase_10 AC 22 ms
7,812 KB
testcase_11 AC 22 ms
7,612 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 9 ms
4,800 KB
testcase_16 AC 12 ms
7,668 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 8 ms
5,108 KB
testcase_19 AC 6 ms
4,380 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 8 ms
4,384 KB
testcase_23 AC 13 ms
7,656 KB
testcase_24 AC 13 ms
7,668 KB
testcase_25 AC 14 ms
7,528 KB
testcase_26 AC 13 ms
7,724 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 12 ms
7,256 KB
testcase_33 AC 13 ms
7,744 KB
testcase_34 AC 13 ms
7,700 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 10 ms
5,628 KB
testcase_37 AC 13 ms
7,772 KB
testcase_38 AC 13 ms
7,348 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 11 ms
6,240 KB
testcase_42 AC 11 ms
6,192 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘yes’ 内:
main.c:59:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   59 |         write(1,"Yes",3);
      |         ^~~~~
main.c:60:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   60 |         _exit(0);
      |         ^~~~~
      |         _Exit
main.c:61:1: 警告: ‘noreturn’ 関数が戻り (return) ます
   61 | }
      | ^
main.c: 関数 ‘no’ 内:
main.c:67:1: 警告: ‘noreturn’ 関数が戻り (return) ます
   67 | }
      | ^

ソースコード

diff #

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

#define rd(v) long v=0;{long _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define rep(v,e) for(long v=0;v<e;++v)

typedef unsigned long ulong;

void radix_sort_aux(ulong*a,ulong*b,int n){
	int c[256];
	for(int i=0;i<256;++i){
		c[i]=0;
	}
	for(int i=0;i<n;++i){
		++c[a[i]&255];
	}
	int t=0;
	for(int i=0;i<256;++i){
		int u=c[i];
		c[i]=t;
		t+=u;
	}
	for(int i=0;i<n;++i){
		b[c[a[i]&255]++]=a[i]>>8|a[i]<<56;
	}
}

void radix_sort(ulong*a,int n){
	static ulong b[200000];
	radix_sort_aux(a,b,n);
	radix_sort_aux(b,a,n);
	radix_sort_aux(a,b,n);
	radix_sort_aux(b,a,n);
	radix_sort_aux(a,b,n);
	radix_sort_aux(b,a,n);
	radix_sort_aux(a,b,n);
	radix_sort_aux(b,a,n);
}

long gcd(long a,long b){
	long x=__builtin_ctzl(a);
	long y=__builtin_ctzl(b);
	a>>=x;
	b>>=y;
	long c;
	while(c=a-b){
		c>>=__builtin_ctzl(c);
		if(c<0){
			b=-c;
		}else{
			a=c;
		}
	}
	return a<<(x<=y?x:y);
}

void yes() __attribute__((noreturn));
void yes(){
	write(1,"Yes",3);
	_exit(0);
}

void no() __attribute__((noreturn));
void no(){
	write(1,"No",2);
	_exit(0);
}

ulong a[200000];

int main(){
	char*mmap();
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd(n);
	long l=0;
	while(*rp){
		rd(x);
		if(x){
			a[l++]=x;
		}
	}
	if(l<2){
		yes();
	}
	radix_sort(a,l);
	long g=a[l-1]-a[0];
	if(!g){
		yes();
	}
	rep(i,l-1){
		long d=a[i+1]-a[i];
		if(!d){
			no();
		}
		g=gcd(g,d);
	}
	if((n-1)*g<a[l-1]-a[0]){
		no();
	}
	yes();
}
0