結果

問題 No.1884 Sequence
ユーザー tailstails
提出日時 2022-03-26 22:14:18
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 7,704 KB
最終ジャッジ日時 2024-04-23 14:06:21
合計ジャッジ時間 2,370 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 0 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 21 ms
7,660 KB
testcase_11 AC 20 ms
7,584 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 12 ms
7,584 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 8 ms
5,376 KB
testcase_23 AC 12 ms
7,680 KB
testcase_24 AC 11 ms
7,588 KB
testcase_25 AC 12 ms
7,424 KB
testcase_26 AC 12 ms
7,680 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 6 ms
5,376 KB
testcase_32 AC 11 ms
7,168 KB
testcase_33 AC 11 ms
7,456 KB
testcase_34 AC 12 ms
7,704 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 8 ms
5,504 KB
testcase_37 AC 12 ms
7,540 KB
testcase_38 AC 11 ms
7,260 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 5 ms
5,376 KB
testcase_41 AC 10 ms
6,144 KB
testcase_42 AC 9 ms
6,144 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'yes':
main.c:59:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   59 |         write(1,"Yes",3);
      |         ^~~~~
main.c:60:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   60 |         _exit(0);
      |         ^~~~~
      |         _Exit
main.c:61:1: warning: 'noreturn' function does return
   61 | }
      | ^
main.c: In function 'no':
main.c:67:1: warning: 'noreturn' function does 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