結果

問題 No.907 Continuous Kadomatu
ユーザー 👑 kmjpkmjp
提出日時 2019-10-12 01:03:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 519 ms / 2,000 ms
コード長 2,276 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 177,972 KB
実行使用メモリ 68,480 KB
最終ジャッジ日時 2024-05-04 13:08:10
合計ジャッジ時間 6,132 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
6,816 KB
testcase_01 AC 15 ms
6,940 KB
testcase_02 AC 15 ms
6,940 KB
testcase_03 AC 15 ms
6,944 KB
testcase_04 AC 15 ms
6,940 KB
testcase_05 AC 49 ms
12,928 KB
testcase_06 AC 15 ms
6,940 KB
testcase_07 AC 24 ms
7,424 KB
testcase_08 AC 39 ms
11,520 KB
testcase_09 AC 31 ms
8,448 KB
testcase_10 AC 63 ms
17,664 KB
testcase_11 AC 90 ms
22,912 KB
testcase_12 AC 236 ms
38,912 KB
testcase_13 AC 225 ms
44,892 KB
testcase_14 AC 238 ms
43,392 KB
testcase_15 AC 222 ms
43,008 KB
testcase_16 AC 257 ms
47,104 KB
testcase_17 AC 270 ms
47,744 KB
testcase_18 AC 240 ms
44,416 KB
testcase_19 AC 293 ms
49,152 KB
testcase_20 AC 17 ms
6,944 KB
testcase_21 AC 18 ms
6,940 KB
testcase_22 AC 17 ms
6,944 KB
testcase_23 AC 519 ms
67,840 KB
testcase_24 AC 404 ms
68,480 KB
testcase_25 AC 15 ms
6,944 KB
testcase_26 AC 15 ms
6,944 KB
testcase_27 AC 15 ms
6,944 KB
testcase_28 AC 15 ms
6,940 KB
testcase_29 AC 14 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int A[202],B[202],X[202],Y[202];
vector<int> V;

ll mo=1000000007;
ll S[202][202],T[202];

ll P[202][402][205];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	S[1][0]=T[1]=1;
	for(i=2;i<=200;i++) {
		FOR(j,i) {
			if(i%2==0) {
				FOR(x,j) S[i][j]+=S[i-1][x];
			}
			else {
				for(x=j;x<i;x++) S[i][j]+=S[i-1][x];
			}
			
			(S[i][j]=S[i][j]%mo*modpow(i))%=mo;
			T[i]+=S[i][j];
		}
		T[i]%=mo;
	}
	for(i=200;i>=2;i--) T[i]=T[i]*modpow(T[i-1])%mo;
	
	
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i]>>B[i];
		V.push_back(A[i]);
		V.push_back(B[i]);
	}
	sort(ALL(V));
	V.erase(unique(ALL(V)),V.end());
	M=V.size()-1;
	FOR(x,M) FOR(y,M) if(V[x]>=A[0]&&V[x]<B[0] && V[y]>=A[1]&&V[y]<B[1]) {
		ll a=(V[x+1]-V[x])*modpow(B[0]-A[0])%mo;
		ll b=(V[y+1]-V[y])*modpow(B[1]-A[1])%mo;
		ll c=a*b%mo;
		if(x<y) {
			(P[1][y][1]+=c)%=mo;
			(P[1][y][0]+=c)%=mo;
		}
		if(x==y) {
			(P[1][y][2]+=c*modpow(2))%=mo;
			(P[1][y][0]+=c*modpow(2))%=mo;
		}
	}
	
	
	for(i=2;i<N;i++) {
		FOR(j,M) if(V[j]>=A[i]&&V[j]<B[i]) {
			ll p=(V[j+1]-V[j])*modpow(B[i]-A[i])%mo;
			if(i%2) {
				FOR(x,j) {
					(P[i][j][1]+=P[i-1][x][0]*p)%=mo;
					(P[i][j][0]+=P[i-1][x][0]*p)%=mo;
				}
			}
			else {
				for(x=j+1;x<M;x++) {
					(P[i][j][1]+=P[i-1][x][0]*p)%=mo;
					(P[i][j][0]+=P[i-1][x][0]*p)%=mo;
				}
			}
			for(x=1;x<=i;x++) {
				(P[i][j][x+1]+=P[i-1][j][x]*p%mo*T[x+1])%=mo;
				(P[i][j][0]+=P[i-1][j][x]*p%mo*T[x+1])%=mo;
			}
		}
	}
	
	ll ret=0;
	FOR(j,M) ret+=P[N-1][j][0];
	cout<<ret%mo<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0