結果
問題 | No.907 Continuous Kadomatu |
ユーザー | LayCurse |
提出日時 | 2019-10-11 23:03:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 660 ms / 2,000 ms |
コード長 | 10,374 bytes |
コンパイル時間 | 2,928 ms |
コンパイル使用メモリ | 224,284 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-25 09:11:31 |
合計ジャッジ時間 | 5,468 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 7 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 4 ms
6,820 KB |
testcase_08 | AC | 6 ms
6,820 KB |
testcase_09 | AC | 4 ms
6,816 KB |
testcase_10 | AC | 10 ms
6,816 KB |
testcase_11 | AC | 14 ms
6,816 KB |
testcase_12 | AC | 26 ms
6,816 KB |
testcase_13 | AC | 28 ms
6,816 KB |
testcase_14 | AC | 30 ms
6,816 KB |
testcase_15 | AC | 32 ms
6,816 KB |
testcase_16 | AC | 33 ms
6,820 KB |
testcase_17 | AC | 34 ms
6,820 KB |
testcase_18 | AC | 30 ms
6,820 KB |
testcase_19 | AC | 33 ms
6,820 KB |
testcase_20 | AC | 14 ms
6,820 KB |
testcase_21 | AC | 9 ms
6,820 KB |
testcase_22 | AC | 8 ms
6,816 KB |
testcase_23 | AC | 660 ms
6,816 KB |
testcase_24 | AC | 624 ms
6,816 KB |
testcase_25 | AC | 2 ms
6,816 KB |
testcase_26 | AC | 2 ms
6,816 KB |
testcase_27 | AC | 2 ms
6,816 KB |
testcase_28 | AC | 2 ms
6,820 KB |
testcase_29 | AC | 2 ms
6,816 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define MD 1000000007 void *wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } struct mint{ static unsigned md; static unsigned W; static unsigned R; static unsigned Rinv; static unsigned mdninv; static unsigned RR; unsigned val; mint(){ } mint(int a){ val = mulR(a); } mint(unsigned a){ val = mulR(a); } mint(long long a){ val = mulR(a); } mint(unsigned long long a){ val = mulR(a); } int get_inv(long long a, int md){ long long t=a; long long s=md; long long u=1; long long v=0; long long 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; } void setmod(unsigned m){ int i; unsigned t; W = 32; md = m; R = (1ULL << W) % md; RR = (unsigned long long)R*R % md; switch(m){ case 104857601: Rinv = 2560000; mdninv = 104857599; break; case 998244353: Rinv = 232013824; mdninv = 998244351; break; case 1000000007: Rinv = 518424770; mdninv = 2226617417U; break; case 1000000009: Rinv = 171601999; mdninv = 737024967; break; case 1004535809: Rinv = 234947584; mdninv = 1004535807; break; case 1007681537: Rinv = 236421376; mdninv = 1007681535; break; case 1012924417: Rinv = 238887936; mdninv = 1012924415; break; case 1045430273: Rinv = 254466304; mdninv = 1045430271; break; case 1051721729: Rinv = 257538304; mdninv = 1051721727; break; default: Rinv = get_inv(R, md); mdninv = 0; t = 0; for(i=(0);i<((int)W);i++){ if(t%2==0){ t+=md; mdninv |= (1U<<i); } t /= 2; } } } unsigned mulR(unsigned a){ return (unsigned long long)a*R%md; } unsigned mulR(int a){ if(a < 0){ a = a%((int)md)+(int)md; } return mulR((unsigned)a); } unsigned mulR(unsigned long long a){ return mulR((unsigned)(a%md)); } unsigned mulR(long long a){ a %= md; if(a < 0){ a += md; } return mulR((unsigned)a); } unsigned reduce(unsigned T){ unsigned m = T * mdninv; unsigned t = (unsigned)((T + (unsigned long long)m*md) >> W); if(t >= md){ t -= md; } return t; } unsigned reduce(unsigned long long T){ unsigned m = (unsigned)T * mdninv; unsigned t = (unsigned)((T + (unsigned long long)m*md) >> W); if(t >= md){ t -= md; } return t; } unsigned get(){ return reduce(val); } mint &operator+=(mint a){ val += a.val; if(val >= md){ val -= md; } return *this; } mint &operator-=(mint a){ if(val < a.val){ val = val + md - a.val; } else{ val -= a.val; } return *this; } mint &operator*=(mint a){ val = reduce((unsigned long long)val*a.val); return *this; } mint &operator/=(mint a){ return *this *= a.inverse(); } mint operator+(mint a){ return mint(*this)+=a; } mint operator-(mint a){ return mint(*this)-=a; } mint operator*(mint a){ return mint(*this)*=a; } mint operator/(mint a){ return mint(*this)/=a; } mint operator+(int a){ return mint(*this)+=mint(a); } mint operator-(int a){ return mint(*this)-=mint(a); } mint operator*(int a){ return mint(*this)*=mint(a); } mint operator/(int a){ return mint(*this)/=mint(a); } mint operator+(long long a){ return mint(*this)+=mint(a); } mint operator-(long long a){ return mint(*this)-=mint(a); } mint operator*(long long a){ return mint(*this)*=mint(a); } mint operator/(long long a){ return mint(*this)/=mint(a); } mint operator-(void){ mint res; if(val){ res.val=md-val; } else{ res.val=0; } return res; } operator bool(void){ return val!=0; } operator int(void){ return get(); } operator long long(void){ return get(); } mint inverse(){ int a = val; int b = md; int u = 1; int v = 0; int t; mint res; while(b){ t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if(u < 0){ u += md; } res.val = (unsigned long long)u*RR % md; return res; } mint pw(unsigned long long b){ mint a(*this); mint res; res.val = R; while(b){ if(b&1){ res *= a; } b >>= 1; a *= a; } return res; } bool operator==(int a){ return mulR(a)==val; } bool operator!=(int a){ return mulR(a)!=val; } } ; unsigned mint::md; unsigned mint::W; unsigned mint::R; unsigned mint::Rinv; unsigned mint::mdninv; unsigned mint::RR; mint operator+(int a, mint b){ return mint(a)+=b; } mint operator-(int a, mint b){ return mint(a)-=b; } mint operator*(int a, mint b){ return mint(a)*=b; } mint operator/(int a, mint b){ return mint(a)/=b; } mint operator+(long long a, mint b){ return mint(a)+=b; } mint operator-(long long a, mint b){ return mint(a)-=b; } mint operator*(long long a, mint b){ return mint(a)*=b; } mint operator/(long long a, mint b){ return mint(a)/=b; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int 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){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } inline void wt_L(mint x){ int i; i = (int)x; wt_L(i); } template<class T> int coordcomp_L(int n1, T arr1[], int n2, T arr2[], int res1[] = NULL, int res2[] = NULL, void *mem = wmem){ int i; int k = 0; pair<T,int> *r; walloc1d(&r, n1+n2, &mem); for(i=(0);i<(n1);i++){ r[i].first = arr1[i]; r[i].second = i; } for(i=(0);i<(n2);i++){ r[n1+i].first = arr2[i]; r[n1+i].second = n1+i; } sort(r, r+n1+n2); for(i=(0);i<(n1+n2);i++){ if(i && r[i].first != r[i-1].first){ k++; } if(r[i].second < n1){ if(res1!=NULL){ res1[r[i].second] = k; } else{ arr1[r[i].second] = k; } } else{ if(res2!=NULL){ res2[r[i].second-n1] = k; } else{ arr2[r[i].second-n1] = k; } } } return k+1; } int N; int A[200]; int B[200]; int x[200]; int y[200]; int v[400]; int m; mint dp[200][401]; mint dp2[200][401]; mint coef[201]; mint dd[201]; mint nn[201]; int main(){ int i, k, n; wmem = memarr; { mint x; x.setmod(MD); } int s; int e; mint res; mint tmp; mint mul; rd(N); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); rd(B[Lj4PdHRW]); } } for(n=(1);n<(N+1);n++){ int i, k; for(i=(0);i<(n);i++){ dd[i] = 0; } dd[n] = 1; for(k=(0);k<(n);k++){ s = n - k; nn[0] = dd[s]; for(i=(1);i<(s);i++){ nn[i] = nn[i-1] + dd[s-i]; } for(i=(0);i<(s);i++){ dd[i] = nn[i]; } } coef[n] = dd[0]; for(i=(1);i<(n+1);i++){ coef[n] /= i; } } m =coordcomp_L(N, A, N, B, x, y)- 1; for(i=(0);i<(N);i++){ v[x[i]] = A[i]; v[y[i]] = B[i]; } for(k=(0);k<(m);k++){ if(x[0] <= k && k < y[0]){ dp[0][k] = dp2[0][k] = mint(v[k+1] - v[k]) / mint(B[0] - A[0]); } } for(i=(1);i<(N);i++){ for(k=(0);k<(m);k++){ if(x[i] <= k && k < y[i]){ int j, z; tmp = mint(v[k+1] - v[k]) / mint(B[i] - A[i]); if(i%2==0){ s = k+1; e = m; } else{ s = 0; e = k; } for(j=(s);j<(e);j++){ dp[i][k] += tmp * dp[i-1][j]; } dp2[i][k] = dp[i][k]; mul = 1; for(z=(i)-1;z>=(0);z--){ if(!(x[z] <= k && k < y[z])){ break; } dp[i][k] += tmp * dp2[z][k] * coef[i-z+1] * mul; mul *= mint(v[k+1] - v[k]) / mint(B[z] - A[z]); } } } } res = 0; for(k=(0);k<(m);k++){ res += dp[N-1][k]; } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20191006-1 // --- original code --- // int N, A[200], B[200]; // int x[200], y[200], v[400], m; // mint dp[200][401], dp2[200][401]; // mint coef[201], dd[201], nn[201]; // { // int s, e; // mint res, tmp, mul; // rd(N,(A,B)(N)); // // rep(n,1,N+1){ // rep(i,n) dd[i] = 0; // dd[n] = 1; // rep(k,n){ // s = n - k; // nn[0] = dd[s]; // rep(i,1,s) nn[i] = nn[i-1] + dd[s-i]; // rep(i,s) dd[i] = nn[i]; // } // coef[n] = dd[0]; // rep(i,1,n+1) coef[n] /= i; // } // // // m = coordcomp(N, A, N, B, x, y) - 1; // rep(i,N) v[x[i]] = A[i], v[y[i]] = B[i]; // // rep(k,m) if(x[0] <= k < y[0]) dp[0][k] = dp2[0][k] = mint(v[k+1] - v[k]) / mint(B[0] - A[0]); // // // rep(i,N) wt("xy",x[i],y[i]); // // rep(i,1,N){ // // wt(i,":",dp[i-1](m)); // // wt(i,":",dp2[i-1](m)); // rep(k,m) if(x[i] <= k < y[i]){ // tmp = mint(v[k+1] - v[k]) / mint(B[i] - A[i]); // if(i%2==0) s = k+1, e = m; // else s = 0, e = k; // rep(j,s,e) dp[i][k] += tmp * dp[i-1][j]; // dp2[i][k] = dp[i][k]; // mul = 1; // rrep(z,i){ // if(!(x[z] <= k < y[z])) break; // dp[i][k] += tmp * dp2[z][k] * coef[i-z+1] * mul; // mul *= mint(v[k+1] - v[k]) / mint(B[z] - A[z]); // } // } // } // // wt(i,":",dp[i-1](m)); // // wt(i,":",dp2[i-1](m)); // // res = 0; // rep(k,m) res += dp[N-1][k]; // wt(res); // }