結果

問題 No.1884 Sequence
ユーザー tailstails
提出日時 2022-03-25 22:30:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,447 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 33,280 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-04-22 07:12:57
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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[65536];
	for(int i=0;i<65536;++i){
		c[i]=0;
	}
	for(int i=0;i<n;++i){
		++c[a[i]&65535];
	}
	int t=0;
	for(int i=0;i<65536;++i){
		int u=c[i];
		c[i]=t;
		t+=u;
	}
	for(int i=0;i<n;++i){
		b[c[a[i]&65535]++]=a[i]>>16|a[i]<<48;
	}
}

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);
}

long gcd(long a,long b){
	if(a==0||b==0){
		return a+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);
	if(a[0]==a[l-1]){
		yes();
	}
	long g=a[l-1]-a[l-2];
	rep(i,l-1){
		g=gcd(g,a[i+1]-a[i]);
	}
	long m=n-1;
	rep(i,l-1){
		long d=a[i+1]-a[i];
		if(!d){
			no();
		}
		m-=d/g;
	}
	if(m<0){
		no();
	}
	yes();
}
0