結果

問題 No.2313 Product of Subsequence (hard)
ユーザー tailstails
提出日時 2023-05-24 21:05:13
言語 C90
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,362 bytes
コンパイル時間 1,459 ms
コンパイル使用メモリ 28,932 KB
実行使用メモリ 6,976 KB
最終ジャッジ日時 2023-08-25 13:22:44
合計ジャッジ時間 8,244 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 222 ms
5,884 KB
testcase_09 AC 35 ms
4,380 KB
testcase_10 AC 119 ms
6,628 KB
testcase_11 AC 39 ms
4,380 KB
testcase_12 AC 102 ms
6,976 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:53:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
 main(){
 ^~~~
main.c: In function ‘main’:
main.c:86:3: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
   write(1,wp,wbuf+sizeof wbuf-wp);
   ^~~~~
main.c:88:2: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
  _exit(0);
  ^~~~~
main.c:88:2: warning: incompatible implicit declaration of built-in function ‘_exit’

ソースコード

diff #

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

char*mmap();

#define rd_skip() while(*rp++>=48)
#define rd(v) long v=0;{long _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);}

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

#define H_BITS 13
#define H_LEN (1<<H_BITS)
#define H_MASK (H_LEN-1)
int h[H_LEN];

long geth(int v){
//	long l=v&H_MASK;
	long l=v+(v>>H_BITS)&H_MASK;
	while(h[l]!=0&&h[l]!=v){
		l=l+1&H_MASK;
	}
	h[l]=v;
	return l;
}

int divn;
int divs[300000];
int divh[300000];

int dp[H_LEN];

#define MD 998244353

main(){
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd_skip();
	rd(k);
	for(long i=1;i*i<=k;++i){
		if(k%i==0){
			divs[divn++]=i;
		}
	}
	for(long j=divn-(divs[divn-1]*divs[divn-1]==k);--j>=0;){
		divs[divn++]=k/divs[j];
	}

	dp[geth(1)]=1;

	while(*rp){
		rd(a);
		a=gcd(k,a);
		for(long j=divn;--j>=0;){
			long c=divs[j];
			long ch=geth(c);
			long b=gcd(k,a*c);
			long bh=geth(b);
			long v=dp[bh]+dp[ch];
			v-=v<MD?0:MD;
			dp[bh]=v;
		}
	}

	{
		long z=dp[geth(k)]-(k==1);
		char wbuf[64],*wp=wbuf+sizeof wbuf;
		wt(z);
		write(1,wp,wbuf+sizeof wbuf-wp);
	}
	_exit(0);

}
0