답안 #389087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389087 2021-04-13T15:34:29 Z mosiashvililuka Boat (APIO16_boat) C++14
36 / 100
2000 ms 20772 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,mod=1000000007LL,sub1,f[3009],DPI[3009],pas,li,dp[3009],dpp[3009],dp2[3009][509],dpp2[3009][509],fct[509],C[3009][509],len[3009],wu[3009];
pair <long long, long long> p[3009],l[5009];
map <long long, long long> m,n;
map <long long, long long>::iterator it,tt;
long long xar(long long q, long long w){
	if(w==0) return 1LL;
	long long qw=xar(q,w/2);
	if(w%2==0) return (qw*qw)%mod; else return ((qw*qw)%mod*q)%mod;
}
long long dv(long long q, long long w){
	return (q*xar(w,mod-2))%mod;
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(i=1; i<=a; i++){
		cin>>p[i].first>>p[i].second;
		if(p[i].first!=p[i].second){
			sub1=1;
		}
	}
	if(sub1==0){
		DPI[a]=1;
		for(i=a-1; i>=1; i--){
			for(j=i+1; j<=a; j++){
				if(p[j].first>p[i].first){
					DPI[i]+=DPI[j];
					if(DPI[i]>=mod) DPI[i]-=mod;
				}
			}
			DPI[i]++;
			if(DPI[i]>=mod) DPI[i]-=mod;
		}
		for(i=1; i<=a; i++){
			pas+=DPI[i];
			if(pas>=mod) pas-=mod;
		}
		cout<<pas;
		return 0;
	}
	for(i=1; i<=a; i++){
		m[p[i].first]=1;
		m[p[i].second]=1;
	}
	
	for(it=m.begin(); it!=m.end(); it++){
		li++;
		l[li].first=(*it).first;
		l[li].second=(*it).first;
		tt=it;tt++;
		if(tt!=m.end()&&(*it).first+1<=(*tt).first-1){
			li++;
			l[li].first=(*it).first+1;
			l[li].second=(*tt).first-1;
		}
	}
	/*cout<<li<<endl;
	for(i=1; i<=li; i++){
		cout<<l[i].first<<" "<<l[i].second<<endl;
	}*/
	for(i=1; i<=li; i++){
		n[l[i].first]=l[i].second;
	}
	for(i=1; i<=li; i++){
		len[i]=l[i].second-l[i].first+1;
		C[i][0]=1;
		for(j=1; j<=min(a,len[i]); j++){
			zx=dv(len[i]-j+1,j);
			C[i][j]=(C[i][j-1]*zx)%mod;
			//cout<<len[i]<<" "<<j<<"  "<<C[i][j]<<endl;
		}
	}
	for(ii=a; ii>=1; ii--){
		for(i=0; i<=li+2; i++){
			dpp[i]=dp[i];
			for(j=0; j<=a+2; j++){
				dpp2[i][j]=dp2[i][j];
			}
		}
		for(i=1; i<=li; i++){
			if(l[i].second<p[ii].first||l[i].first>p[ii].second) continue;
			wu[i]++;
			for(j=i+1; j<=li; j++){
				/*dpp[i]+=dp[j]*len[i];
				dpp[i]%=mod;*/
				dpp2[i][1]+=dp[j];
				if(dpp2[i][1]>=mod) dpp2[i][1]-=mod;
			}
			dpp2[i][1]++;
			if(dpp2[i][1]>=mod) dpp2[i][1]-=mod;
			for(j=1; j<wu[i]; j++){
				dpp2[i][j+1]+=dp2[i][j];
				if(dpp2[i][j+1]>=mod) dpp2[i][j+1]-=mod;
			}
			dpp[i]=0;
			for(j=1; j<=wu[i]; j++){
				//if(j>len[i]) break;
				dpp[i]+=dpp2[i][j]*C[i][j];
				//if(dpp[i]>=mod) dpp[i]-=mod;
				dpp[i]%=mod;
			}
		}
		for(i=1; i<=li; i++){
			dp[i]=dpp[i];
			for(j=0; j<=a+2; j++){
				dp2[i][j]=dpp2[i][j];
			}
		}
/*		for(i=1; i<=li; i++) cout<<dp[i]<<" ";
		cout<<endl;*/
	}
	//cout<<dp2[2][1]<<endl;
	
	pas=0;
	for(i=1; i<=li; i++){
		pas+=dp[i];
		if(pas>=mod) pas-=mod;
	}
	cout<<pas;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1680 ms 20552 KB Output is correct
22 Correct 1686 ms 20772 KB Output is correct
23 Correct 1612 ms 20356 KB Output is correct
24 Correct 1700 ms 20644 KB Output is correct
25 Correct 1650 ms 20220 KB Output is correct
26 Correct 1941 ms 19288 KB Output is correct
27 Correct 1950 ms 19524 KB Output is correct
28 Correct 1964 ms 19524 KB Output is correct
29 Execution timed out 2003 ms 19520 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 5068 KB Output is correct
2 Correct 23 ms 5172 KB Output is correct
3 Correct 25 ms 5068 KB Output is correct
4 Correct 25 ms 5068 KB Output is correct
5 Correct 25 ms 5164 KB Output is correct
6 Correct 30 ms 5068 KB Output is correct
7 Correct 31 ms 5100 KB Output is correct
8 Correct 31 ms 5068 KB Output is correct
9 Correct 34 ms 5068 KB Output is correct
10 Correct 30 ms 5068 KB Output is correct
11 Correct 25 ms 5068 KB Output is correct
12 Correct 23 ms 5068 KB Output is correct
13 Correct 24 ms 5068 KB Output is correct
14 Correct 25 ms 5172 KB Output is correct
15 Correct 25 ms 5068 KB Output is correct
16 Correct 10 ms 2380 KB Output is correct
17 Correct 9 ms 2428 KB Output is correct
18 Correct 9 ms 2364 KB Output is correct
19 Correct 9 ms 2440 KB Output is correct
20 Correct 10 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1680 ms 20552 KB Output is correct
22 Correct 1686 ms 20772 KB Output is correct
23 Correct 1612 ms 20356 KB Output is correct
24 Correct 1700 ms 20644 KB Output is correct
25 Correct 1650 ms 20220 KB Output is correct
26 Correct 1941 ms 19288 KB Output is correct
27 Correct 1950 ms 19524 KB Output is correct
28 Correct 1964 ms 19524 KB Output is correct
29 Execution timed out 2003 ms 19520 KB Time limit exceeded
30 Halted 0 ms 0 KB -