結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー tailstails
提出日時 2021-07-06 14:32:55
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,157 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 31,152 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-09-14 04:22:33
合計ジャッジ時間 5,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,764 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:26:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   26 | main(){
      | ^~~~
main.c: 関数 ‘main’ 内:
main.c:75:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   75 |         write(1,wp,wbuf+sizeof wbuf-wp);
      |         ^~~~~
main.c:76:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   76 |         _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);}

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

main(){
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd(p);
	rd(q);
	rd_skip();
	long r=0;
	if(p+q==0){
		while(*rp){
			long x=*rp==48;
			rd_skip();
			long y=*rp==48;
			rd_skip();
			r+=x&y;
		}
	}else{
		long g=gcd(p,q);
		long b=__builtin_ctzl(g);
		unsigned long t,e;
		{
			long x=g>>b;
			t=~0ul/x;
			e=x;
			e*=2-x*e;
			e*=2-x*e;
			e*=2-x*e;
			e*=2-x*e;
			e*=2-x*e;
		}
		p=(p>>b)*e;
		q=(q>>b)*e;
		long m=(1<<b)-1;
		long f=!(p&q&1);
		while(*rp){
			rp+=*rp==45;
			rd(x);
			rp+=*rp==45;
			rd(y);
			if(!((x|y)&m)){
				x=(x>>b)*e;
				y=(y>>b)*e;
				if(x<=t&&y<=t){
					r+=f|~(x^y)&1;
				}
			}
		}
	}

	char wbuf[64],*wp=wbuf+sizeof wbuf;
	wt(r);
	write(1,wp,wbuf+sizeof wbuf-wp);
	_exit(0);
}
0