結果
問題 | No.187 中華風 (Hard) |
ユーザー | LayCurse |
提出日時 | 2015-03-24 15:25:16 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 318 ms / 3,000 ms |
コード長 | 5,954 bytes |
コンパイル時間 | 1,478 ms |
コンパイル使用メモリ | 164,648 KB |
実行使用メモリ | 10,368 KB |
最終ジャッジ日時 | 2024-06-29 00:31:26 |
合計ジャッジ時間 | 6,216 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 217 ms
10,240 KB |
testcase_03 | AC | 219 ms
10,368 KB |
testcase_04 | AC | 315 ms
10,240 KB |
testcase_05 | AC | 316 ms
10,240 KB |
testcase_06 | AC | 316 ms
10,240 KB |
testcase_07 | AC | 318 ms
10,368 KB |
testcase_08 | AC | 197 ms
10,240 KB |
testcase_09 | AC | 190 ms
10,240 KB |
testcase_10 | AC | 196 ms
10,240 KB |
testcase_11 | AC | 317 ms
10,112 KB |
testcase_12 | AC | 317 ms
10,240 KB |
testcase_13 | AC | 27 ms
10,240 KB |
testcase_14 | AC | 27 ms
10,368 KB |
testcase_15 | AC | 206 ms
10,240 KB |
testcase_16 | AC | 214 ms
10,240 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 237 ms
8,704 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 316 ms
10,112 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’: main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | void reader(double *x){scanf("%lf",x);} | ~~~~~^~~~~~~~~ main.cpp: In function ‘long long unsigned int mulmod(long long unsigned int, long long unsigned int, long long unsigned int)’: main.cpp:40:85: warning: ‘q’ is used uninitialized [-Wuninitialized] 40 | ull mulmod(ull x, ull y, ull m){int k,p=2;ull i,j,c,f,l,h,d,e,a,q,r,b=0xffffffffULL;if(m<=q)return x*y%m;i=x&b;j=x>>32;c=y&b;f=y>>32;h=j*f;l=i*c;a=(l>>32)+j*c;h+=a>>32;a&=b;a+=i*f;h+=a>>32;l=l&b|(a&b)<<32;k=numberOfLeadingZeros(m);h=h<<k|l>>(64-k);l<<=k;m<<=k;d=m>>32;e=m&b;while(p--){r=h/d*e;h=h%d<<32|l>>32;l=(l&b)<<32;if(h<r)h+=m-r;else h-=r;if(h>m)h+=m;}return h>>k;} | ^~
ソースコード
#include<bits/stdc++.h> using namespace std; #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) #define mygc(c) (c)=getchar_unlocked() #define mypc(c) putchar_unlocked(c) #define ll long long #define ull unsigned ll void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(double *x){scanf("%lf",x);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);} template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);} template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(double x, char c){printf("%.15f",x);mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);} template<class T> void writerLn(T x){writer(x,'\n');} template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');} template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');} template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');} char memarr[17000000]; void *mem = memarr; #define MD 1000000007 template<class T> void sort(int N, T a[], void *mem = NULL){sort(a,a+N);} template<class T1, class T2> void sort(int N, T1 a[], T2 b[], void *mem){int i;pair<T1,T2> *r=(pair<T1, T2>*)mem;rep(i,N)r[i].first=a[i],r[i].second=b[i];sort(r,r+N);rep(i,N)a[i]=r[i].first,b[i]=r[i].second;} template<class T1, class T2, class T3> void sort(int N, T1 a[], T2 b[], T3 c[], void *mem){int i;pair<T1,pair<T2,T3> > *r=(pair<T1,pair<T2,T3> >*)mem;rep(i,N)r[i].first=a[i],r[i].second.first=b[i],r[i].second.second=c[i];sort(r,r+N);rep(i,N)a[i]=r[i].first,b[i]=r[i].second.first,c[i]=r[i].second.second;} template<class T1, class T2, class T3, class T4> void sort(int N, T1 a[], T2 b[], T3 c[], T4 d[], void *mem){int i;pair<pair<T1,T2>,pair<T3,T4> > *r=(pair<pair<T1,T2>,pair<T3,T4> >*)mem;rep(i,N)r[i].first.first=a[i],r[i].first.second=b[i],r[i].second.first=c[i],r[i].second.second=d[i];sort(r,r+N);rep(i,N)a[i]=r[i].first.first,b[i]=r[i].first.second,c[i]=r[i].second.first,d[i]=r[i].second.second;} int numberOfLeadingZeros(ull x){int r=56;unsigned l=x,h=x>>32;static int t[256]={8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};if(h)r-=32,l=h;if(l&0xffff0000U)r-=16,l>>=16;if(l&0x0000ff00U)r-=8,l>>=8;return r+t[l];} ull mulmod(ull x, ull y, ull m){int k,p=2;ull i,j,c,f,l,h,d,e,a,q,r,b=0xffffffffULL;if(m<=q)return x*y%m;i=x&b;j=x>>32;c=y&b;f=y>>32;h=j*f;l=i*c;a=(l>>32)+j*c;h+=a>>32;a&=b;a+=i*f;h+=a>>32;l=l&b|(a&b)<<32;k=numberOfLeadingZeros(m);h=h<<k|l>>(64-k);l<<=k;m<<=k;d=m>>32;e=m&b;while(p--){r=h/d*e;h=h%d<<32|l>>32;l=(l&b)<<32;if(h<r)h+=m-r;else h-=r;if(h>m)h+=m;}return h>>k;} void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){ll d=1,e=0,f,g=0,h=1,i,z,q;while(y)q=x/y,z=x%y,f=d-q*e,i=g-q*h,x=y,y=z,d=e,e=f,g=h,h=i;*c=x;*a=d;*b=g;} template<class T> T GCD(T a,T b){T r; while(a){r=b; b=a; a=r%a;} return b;} int get_inv(ll a, int md){ll t=a,s=md,u=1,v=0,e;while(s){e=t/s;t-=e*s;u-=e*v;swap(t,s);swap(u,v);}if(u<0)u+=md;return u;} ll chineseRemainder(int sz, ll val[], ll md[]){int i;ll m=1,n,a,b,c,r=0;if(sz==1)return val[0];rep(i,sz)m*=md[i];rep(i,sz){n=m/md[i];extended_euclid(md[i],n,&c,&a,&b);b=n*b%m;if(b<0)b+=m;r+=mulmod(b,val[i],m);if(r>=m)r%=m;}return r;} int chineseRemainderPreCalc(int sz, ll val[], ll md[], void *mem){int i,j,x,f;ll k,m,t,*z=(ll*)mem,*p=z+sz;rep(i,sz)REP(j,i+1,sz){k=GCD(md[i],md[j]);if(k==1)continue;f=0;if(k%2==0){p[f++]=2;while(k%2==0)k/=2;}for(m=3;m*m<=k;m+=2)if(k%m==0){p[f++]=m;while(k%m==0)k/=m;}if(k>1)p[f++]=k;rep(m,f){x=0;rep(k,sz){t=md[k];z[k]=1;while(t%p[m]==0)t/=p[m],z[k]*=p[m];if(z[k]>z[x])x=k;}rep(k,sz)if(x!=k){if(val[k]%z[k]!=val[x]%z[k])return 0;md[k]/=z[k];val[k]%=md[k];}}}sort(sz,md,val,mem);return 1;} ll chineseRemainder(int sz, ll val[], ll md[], ll inv[], ll rmd, void *mem){int i,j;ll k,*m=(ll*)mem;rep(i,sz)m[i]=val[i];rep(i,sz)rep(j,i){k=m[i]-m[j];if(k<0)k+=md[i];m[i]=k*inv[i*sz+j]%md[i];}k=0;for(i=sz-1;i>=0;i--)k=(mulmod(md[i]%rmd,k,rmd)+m[i])%rmd;return k;} void chineseRemainderGetInv(int sz, ll md[], ll inv[]){int i,j;rep(i,sz)rep(j,i)inv[i*sz+j]=get_inv(md[j],md[i]);} int N; ll X[1111], Y[1111]; ll inv[1111111]; int main(){ int i, j, k, mx, id; ll res, m; reader(&N); rep(i,N){ reader(X+i,Y+i); assert(0 <= X[i] && X[i] < Y[i] && Y[i] <= 1000000000); } k = chineseRemainderPreCalc(N, X, Y, mem); if(k) res = chineseRemainder(N, X, Y); else res = -1; if(k){ chineseRemainderGetInv(N, Y, inv); rep(i,N) if(X[i]) break; if(i < N){ res = chineseRemainder(N, X, Y, inv, MD, mem); } else { res = 1; rep(i,N) res = res * Y[i] % MD; } } else { res = -1; } writerLn(res); return 0; }