結果

問題 No.2709 1975 Powers
ユーザー tailstails
提出日時 2024-04-01 10:34:29
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,616 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 26,684 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-01 10:34:30
合計ジャッジ時間 1,234 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 3 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 0 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 1 ms
6,548 KB
testcase_11 AC 1 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 1 ms
6,548 KB
testcase_15 AC 1 ms
6,548 KB
testcase_16 AC 1 ms
6,548 KB
testcase_17 AC 1 ms
6,548 KB
testcase_18 AC 1 ms
6,548 KB
testcase_19 AC 3 ms
6,548 KB
testcase_20 AC 1 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 AC 3 ms
6,548 KB
testcase_23 AC 3 ms
6,548 KB
testcase_24 AC 3 ms
6,548 KB
testcase_25 AC 3 ms
6,548 KB
testcase_26 AC 3 ms
6,548 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:59: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
    7 | #define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
      |                                                           ^~~~~
main.c:83:17: note: in expansion of macro ‘wt1’
   83 |                 wt1(z);
      |                 ^~~
main.c:85:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
   85 |         _exit(0);
      |         ^~~~~
main.c:85:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]

ソースコード

diff #

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

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) ({ulong _z=v;do*--wp=_z%10+48;while(_z/=10);})
#define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
#define rep(v,e) for(typeof(e) v=0;v<e;++v)
#define rrep(v,e) for(typeof(e) v=e;v--;)
#define div_p(x) ((x)*inv_p>>64)
#define mod_p(x) (x-div_p(x)*p)
#define aaa_p(x) (x-=x>=p?p:0)

typedef unsigned long ulong;

ulong h[2000000/64+1];
unsigned as[200];
int d[100000];
int m10[200],m9[200],m7[200],m5[200];

int main(){
	int n;
	unsigned p,q;
	{
		rd_init();
		n=rd();
		p=rd();
		q=rd();
		rep(i,n){
			int a=rd();
			h[a>>6]|=1ul<<a;
		}
	}
	{
		int k=0;
		rep(i,2000000/64+1){
			if(h[i]){
				rep(j,64){
					if(h[i]&1ul<<j){
						as[k++]=i<<6|j;
					}
				}
			}
		}
	}
	{
		unsigned __int128 inv_p=((__int128)1<<64)/p;
		int z=0;
		rep(i,n){
			ulong a10=10,a9=9,a7=7,a5=5;
			ulong b10=1,b9=1,b7=1,b5=1;
			for(unsigned k=as[i];k;k>>=1){
				if(k&1){
					b10=mod_p(b10*a10);
					b9=mod_p(b9*a9);
					b7=mod_p(b7*a7);
					b5=mod_p(b5*a5);
				}
				a10=mod_p(a10*a10);
				a9=mod_p(a9*a9);
				a7=mod_p(a7*a7);
				a5=mod_p(a5*a5);
			}
			m10[i]=b10;
			m9[i]=b9;
			m7[i]=b7;
			m5[i]=b5;
		}
		rrep(ci,n){
			unsigned cv=p-q+m7[ci];
			aaa_p(cv);
			rrep(bi,ci){
				unsigned bv=cv+m9[bi];
				aaa_p(bv);
				rrep(ai,bi){
					unsigned av=bv+m10[ai];
					aaa_p(av);
					z+=d[av];
				}
			}
			d[m5[ci]?p-m5[ci]:0]+=1;
		}
		wt1(z);
	}
	_exit(0);
}
0