結果
問題 | No.907 Continuous Kadomatu |
ユーザー | LayCurse |
提出日時 | 2019-10-12 03:22:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 535 ms / 2,000 ms |
コード長 | 9,084 bytes |
コンパイル時間 | 2,881 ms |
コンパイル使用メモリ | 223,944 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-26 09:24:31 |
合計ジャッジ時間 | 5,137 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 7 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 3 ms
5,248 KB |
testcase_08 | AC | 5 ms
5,248 KB |
testcase_09 | AC | 3 ms
5,248 KB |
testcase_10 | AC | 9 ms
5,248 KB |
testcase_11 | AC | 11 ms
5,248 KB |
testcase_12 | AC | 23 ms
5,248 KB |
testcase_13 | AC | 26 ms
5,248 KB |
testcase_14 | AC | 27 ms
5,248 KB |
testcase_15 | AC | 26 ms
5,248 KB |
testcase_16 | AC | 28 ms
5,248 KB |
testcase_17 | AC | 30 ms
5,248 KB |
testcase_18 | AC | 26 ms
5,248 KB |
testcase_19 | AC | 30 ms
5,248 KB |
testcase_20 | AC | 14 ms
5,248 KB |
testcase_21 | AC | 8 ms
5,248 KB |
testcase_22 | AC | 7 ms
5,248 KB |
testcase_23 | AC | 535 ms
5,248 KB |
testcase_24 | AC | 533 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define MD (1000000007U) #define MINT_W (32U) #define MINT_R (294967268U) #define MINT_RR (582344008U) #define MINT_MDNINV (2226617417U) 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{ 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); } inline unsigned mulR(unsigned a){ return (unsigned long long)a*MINT_R%MD; } inline unsigned mulR(int a){ if(a < 0){ a = a%((int)MD)+(int)MD; } return mulR((unsigned)a); } inline unsigned mulR(unsigned long long a){ return mulR((unsigned)(a%MD)); } inline unsigned mulR(long long a){ a %= MD; if(a < 0){ a += MD; } return mulR((unsigned)a); } inline unsigned reduce(unsigned T){ unsigned m = T * MINT_MDNINV; unsigned t = (unsigned)((T + (unsigned long long)m*MD) >> MINT_W); if(t >= MD){ t -= MD; } return t; } inline unsigned reduce(unsigned long long T){ unsigned m = (unsigned)T * MINT_MDNINV; unsigned t = (unsigned)((T + (unsigned long long)m*MD) >> MINT_W); if(t >= MD){ t -= MD; } return t; } inline unsigned get(){ return reduce(val); } inline Mint &operator+=(Mint a){ val += a.val; if(val >= MD){ val -= MD; } return *this; } inline Mint &operator-=(Mint a){ if(val < a.val){ val = val + MD - a.val; } else{ val -= a.val; } return *this; } inline Mint &operator*=(Mint a){ val = reduce((unsigned long long)val*a.val); return *this; } inline Mint &operator/=(Mint a){ return *this *= a.inverse(); } inline Mint operator+(Mint a){ return Mint(*this)+=a; } inline Mint operator-(Mint a){ return Mint(*this)-=a; } inline Mint operator*(Mint a){ return Mint(*this)*=a; } inline Mint operator/(Mint a){ return Mint(*this)/=a; } inline Mint operator+(int a){ return Mint(*this)+=Mint(a); } inline Mint operator-(int a){ return Mint(*this)-=Mint(a); } inline Mint operator*(int a){ return Mint(*this)*=Mint(a); } inline Mint operator/(int a){ return Mint(*this)/=Mint(a); } inline Mint operator+(long long a){ return Mint(*this)+=Mint(a); } inline Mint operator-(long long a){ return Mint(*this)-=Mint(a); } inline Mint operator*(long long a){ return Mint(*this)*=Mint(a); } inline Mint operator/(long long a){ return Mint(*this)/=Mint(a); } inline Mint operator-(void){ Mint res; if(val){ res.val=MD-val; } else{ res.val=0; } return res; } inline operator bool(void){ return val!=0; } inline operator int(void){ return get(); } inline operator long long(void){ return get(); } inline 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*MINT_RR % MD; return res; } inline Mint pw(unsigned long long b){ Mint a(*this); Mint res; res.val = MINT_R; while(b){ if(b&1){ res *= a; } b >>= 1; a *= a; } return res; } inline bool operator==(int a){ return mulR(a)==val; } inline bool operator!=(int a){ return mulR(a)!=val; } } ; inline Mint operator+(int a, Mint b){ return Mint(a)+=b; } inline Mint operator-(int a, Mint b){ return Mint(a)-=b; } inline Mint operator*(int a, Mint b){ return Mint(a)*=b; } inline Mint operator/(int a, Mint b){ return Mint(a)/=b; } inline Mint operator+(long long a, Mint b){ return Mint(a)+=b; } inline Mint operator-(long long a, Mint b){ return Mint(a)-=b; } inline Mint operator*(long long a, Mint b){ return Mint(a)*=b; } inline 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; 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 20191012-1 [beta] // --- 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); // }