Submission #142986

# Submission time Handle Problem Language Result Execution time Memory
142986 2019-08-12T13:59:40 Z IC_COLDSTOP Boat (APIO16_boat) C++17
100 / 100
696 ms 12536 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define REP(i,a,b) for(int i=a; i<b; i++)

const int MX=5e2+3, mod=1e9+7;

int n, m, dp[10][MX*2][2*MX], l[MX], r[MX], num[2*MX], p[MX*2];
map<int,int> mark;
vector<int> vec;

int pw(int a, int b){
	if(!b) return 1;
	int nsf=pw(a,b/2);
	nsf=nsf*nsf%mod;
	if(b&1) nsf*=a;
	return nsf%mod;
}

int32_t main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	REP(i,1,MX*2) p[i]=pw(i,mod-2);
	cin>>n;
	REP(i,0,n){
		cin>>l[i]>>r[i];
		r[i]++;
		if(!mark[l[i]]) mark[l[i]]=1, vec.pb(l[i]);
		if(!mark[r[i]]) mark[r[i]]=1, vec.pb(r[i]);
	}
	m=vec.size();
	//cout<<m<<endl;
	sort(vec.begin(), vec.end());
	int mm=0;
	dp[mm][0][0]=1;
	REP(j,1,m){
		dp[mm][j][0]=dp[mm][j-1][0]+dp[mm][j-1][1];
		if(l[0]<vec[j] && r[0]>=vec[j]) dp[mm][j][1]=(vec[j]-vec[j-1])%mod, num[j]++;
	//	cout<<j<<" "<<dp[mm][j][0]<<" "<<dp[mm][j][1]<<" "<<vec[j]<<" "<<vec[j-1]<<endl;
	}
	REP(i,1,n){
		mm^=1;
		REP(j,1,m){
			dp[mm][j][0]=0;
			if(j>1) REP(w,0,num[j-1]+1){
				dp[mm][j][0]=(dp[mm][j-1][w]+dp[mm][j][0])%mod;
			//	if(i==2 && j==2) cout<<" B "<<dp[mm][j][0]<<" "<<dp[mm][j-1][w]<<endl;
			}
			else dp[mm][j][0]=1;
			int flg=0, cnt=vec[j]-vec[j-1];
			if(l[i]<vec[j] && r[i]>=vec[j]) flg=1, num[j]++;
			REP(w,1,num[j]+1){
				dp[mm][j][w]=dp[mm^1][j][w];
				if(flg){
					dp[mm][j][w]=((ll)dp[mm][j][w] +  (ll)dp[mm^1][j][w-1]  *  (cnt-w+1) %mod  *  p[w]%mod )%mod;
				}
			}
			//cout<<i<<" "<<j<<" "<<flg<<" "<<num[j]<<endl;
		}
	}
	//cout<<endl;
	int sum=0;
	REP(w,0,MX*2){
		sum=(sum+dp[mm][m-1][w])%mod;
		//cout<<w<<" "<<dp[mm][m-1][w]<<" "<<dp[mm][m-2][w]<<" "<<dp[mm][m-3][w]<<" "<<dp[mm^1][m-1][w]<<" "<<dp[mm^1][m-2][w]<<" "<<dp[mm^1][m-3][w]<<endl;
	}
	cout<<sum-1<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8440 KB Output is correct
2 Correct 14 ms 8440 KB Output is correct
3 Correct 16 ms 8440 KB Output is correct
4 Correct 14 ms 8440 KB Output is correct
5 Correct 14 ms 8440 KB Output is correct
6 Correct 14 ms 8440 KB Output is correct
7 Correct 14 ms 8440 KB Output is correct
8 Correct 16 ms 8444 KB Output is correct
9 Correct 14 ms 8440 KB Output is correct
10 Correct 14 ms 8440 KB Output is correct
11 Correct 13 ms 8440 KB Output is correct
12 Correct 14 ms 8440 KB Output is correct
13 Correct 14 ms 8568 KB Output is correct
14 Correct 14 ms 8440 KB Output is correct
15 Correct 14 ms 8440 KB Output is correct
16 Correct 5 ms 1844 KB Output is correct
17 Correct 5 ms 1912 KB Output is correct
18 Correct 6 ms 1912 KB Output is correct
19 Correct 5 ms 1912 KB Output is correct
20 Correct 6 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8440 KB Output is correct
2 Correct 14 ms 8440 KB Output is correct
3 Correct 16 ms 8440 KB Output is correct
4 Correct 14 ms 8440 KB Output is correct
5 Correct 14 ms 8440 KB Output is correct
6 Correct 14 ms 8440 KB Output is correct
7 Correct 14 ms 8440 KB Output is correct
8 Correct 16 ms 8444 KB Output is correct
9 Correct 14 ms 8440 KB Output is correct
10 Correct 14 ms 8440 KB Output is correct
11 Correct 13 ms 8440 KB Output is correct
12 Correct 14 ms 8440 KB Output is correct
13 Correct 14 ms 8568 KB Output is correct
14 Correct 14 ms 8440 KB Output is correct
15 Correct 14 ms 8440 KB Output is correct
16 Correct 5 ms 1844 KB Output is correct
17 Correct 5 ms 1912 KB Output is correct
18 Correct 6 ms 1912 KB Output is correct
19 Correct 5 ms 1912 KB Output is correct
20 Correct 6 ms 1912 KB Output is correct
21 Correct 367 ms 10200 KB Output is correct
22 Correct 365 ms 10192 KB Output is correct
23 Correct 335 ms 10056 KB Output is correct
24 Correct 357 ms 10104 KB Output is correct
25 Correct 377 ms 10360 KB Output is correct
26 Correct 612 ms 10844 KB Output is correct
27 Correct 614 ms 11128 KB Output is correct
28 Correct 599 ms 10972 KB Output is correct
29 Correct 593 ms 10848 KB Output is correct
30 Correct 16 ms 8440 KB Output is correct
31 Correct 16 ms 8440 KB Output is correct
32 Correct 15 ms 8440 KB Output is correct
33 Correct 16 ms 8568 KB Output is correct
34 Correct 15 ms 8440 KB Output is correct
35 Correct 18 ms 8440 KB Output is correct
36 Correct 16 ms 8440 KB Output is correct
37 Correct 18 ms 8440 KB Output is correct
38 Correct 17 ms 8444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2168 KB Output is correct
2 Correct 6 ms 2040 KB Output is correct
3 Correct 7 ms 2040 KB Output is correct
4 Correct 7 ms 2088 KB Output is correct
5 Correct 7 ms 2144 KB Output is correct
6 Correct 9 ms 2168 KB Output is correct
7 Correct 10 ms 2168 KB Output is correct
8 Correct 9 ms 2168 KB Output is correct
9 Correct 9 ms 2168 KB Output is correct
10 Correct 9 ms 2168 KB Output is correct
11 Correct 8 ms 2168 KB Output is correct
12 Correct 7 ms 2040 KB Output is correct
13 Correct 8 ms 2040 KB Output is correct
14 Correct 7 ms 2040 KB Output is correct
15 Correct 7 ms 2040 KB Output is correct
16 Correct 5 ms 1400 KB Output is correct
17 Correct 5 ms 1272 KB Output is correct
18 Correct 5 ms 1400 KB Output is correct
19 Correct 5 ms 1272 KB Output is correct
20 Correct 5 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8440 KB Output is correct
2 Correct 14 ms 8440 KB Output is correct
3 Correct 16 ms 8440 KB Output is correct
4 Correct 14 ms 8440 KB Output is correct
5 Correct 14 ms 8440 KB Output is correct
6 Correct 14 ms 8440 KB Output is correct
7 Correct 14 ms 8440 KB Output is correct
8 Correct 16 ms 8444 KB Output is correct
9 Correct 14 ms 8440 KB Output is correct
10 Correct 14 ms 8440 KB Output is correct
11 Correct 13 ms 8440 KB Output is correct
12 Correct 14 ms 8440 KB Output is correct
13 Correct 14 ms 8568 KB Output is correct
14 Correct 14 ms 8440 KB Output is correct
15 Correct 14 ms 8440 KB Output is correct
16 Correct 5 ms 1844 KB Output is correct
17 Correct 5 ms 1912 KB Output is correct
18 Correct 6 ms 1912 KB Output is correct
19 Correct 5 ms 1912 KB Output is correct
20 Correct 6 ms 1912 KB Output is correct
21 Correct 367 ms 10200 KB Output is correct
22 Correct 365 ms 10192 KB Output is correct
23 Correct 335 ms 10056 KB Output is correct
24 Correct 357 ms 10104 KB Output is correct
25 Correct 377 ms 10360 KB Output is correct
26 Correct 612 ms 10844 KB Output is correct
27 Correct 614 ms 11128 KB Output is correct
28 Correct 599 ms 10972 KB Output is correct
29 Correct 593 ms 10848 KB Output is correct
30 Correct 16 ms 8440 KB Output is correct
31 Correct 16 ms 8440 KB Output is correct
32 Correct 15 ms 8440 KB Output is correct
33 Correct 16 ms 8568 KB Output is correct
34 Correct 15 ms 8440 KB Output is correct
35 Correct 18 ms 8440 KB Output is correct
36 Correct 16 ms 8440 KB Output is correct
37 Correct 18 ms 8440 KB Output is correct
38 Correct 17 ms 8444 KB Output is correct
39 Correct 7 ms 2168 KB Output is correct
40 Correct 6 ms 2040 KB Output is correct
41 Correct 7 ms 2040 KB Output is correct
42 Correct 7 ms 2088 KB Output is correct
43 Correct 7 ms 2144 KB Output is correct
44 Correct 9 ms 2168 KB Output is correct
45 Correct 10 ms 2168 KB Output is correct
46 Correct 9 ms 2168 KB Output is correct
47 Correct 9 ms 2168 KB Output is correct
48 Correct 9 ms 2168 KB Output is correct
49 Correct 8 ms 2168 KB Output is correct
50 Correct 7 ms 2040 KB Output is correct
51 Correct 8 ms 2040 KB Output is correct
52 Correct 7 ms 2040 KB Output is correct
53 Correct 7 ms 2040 KB Output is correct
54 Correct 5 ms 1400 KB Output is correct
55 Correct 5 ms 1272 KB Output is correct
56 Correct 5 ms 1400 KB Output is correct
57 Correct 5 ms 1272 KB Output is correct
58 Correct 5 ms 1272 KB Output is correct
59 Correct 410 ms 11128 KB Output is correct
60 Correct 379 ms 11036 KB Output is correct
61 Correct 383 ms 10896 KB Output is correct
62 Correct 419 ms 11256 KB Output is correct
63 Correct 395 ms 11060 KB Output is correct
64 Correct 687 ms 12292 KB Output is correct
65 Correct 696 ms 12420 KB Output is correct
66 Correct 692 ms 12368 KB Output is correct
67 Correct 685 ms 12472 KB Output is correct
68 Correct 688 ms 12536 KB Output is correct
69 Correct 408 ms 10884 KB Output is correct
70 Correct 430 ms 11128 KB Output is correct
71 Correct 425 ms 11128 KB Output is correct
72 Correct 442 ms 11108 KB Output is correct
73 Correct 441 ms 11128 KB Output is correct
74 Correct 78 ms 2364 KB Output is correct
75 Correct 78 ms 2424 KB Output is correct
76 Correct 79 ms 2296 KB Output is correct
77 Correct 79 ms 2424 KB Output is correct
78 Correct 79 ms 2296 KB Output is correct