Submission #142990

# Submission time Handle Problem Language Result Execution time Memory
142990 2019-08-12T14:11:33 Z IC_COLDSTOP Boat (APIO16_boat) C++17
100 / 100
691 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();
	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]++;
	}
	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;
			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;
			}
		}
	}
	int sum=0;
	REP(w,0,MX*2) sum=(sum+dp[mm][m-1][w])%mod;
	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 14 ms 8440 KB Output is correct
4 Correct 14 ms 8568 KB Output is correct
5 Correct 15 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 14 ms 8440 KB Output is correct
9 Correct 14 ms 8440 KB Output is correct
10 Correct 14 ms 8440 KB Output is correct
11 Correct 14 ms 8440 KB Output is correct
12 Correct 14 ms 8440 KB Output is correct
13 Correct 14 ms 8440 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 1784 KB Output is correct
17 Correct 5 ms 1912 KB Output is correct
18 Correct 5 ms 1784 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 14 ms 8440 KB Output is correct
4 Correct 14 ms 8568 KB Output is correct
5 Correct 15 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 14 ms 8440 KB Output is correct
9 Correct 14 ms 8440 KB Output is correct
10 Correct 14 ms 8440 KB Output is correct
11 Correct 14 ms 8440 KB Output is correct
12 Correct 14 ms 8440 KB Output is correct
13 Correct 14 ms 8440 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 1784 KB Output is correct
17 Correct 5 ms 1912 KB Output is correct
18 Correct 5 ms 1784 KB Output is correct
19 Correct 5 ms 1912 KB Output is correct
20 Correct 6 ms 1912 KB Output is correct
21 Correct 375 ms 10332 KB Output is correct
22 Correct 367 ms 10284 KB Output is correct
23 Correct 335 ms 9976 KB Output is correct
24 Correct 359 ms 10168 KB Output is correct
25 Correct 377 ms 10360 KB Output is correct
26 Correct 608 ms 10952 KB Output is correct
27 Correct 618 ms 11128 KB Output is correct
28 Correct 600 ms 11000 KB Output is correct
29 Correct 596 ms 10844 KB Output is correct
30 Correct 15 ms 8444 KB Output is correct
31 Correct 15 ms 8440 KB Output is correct
32 Correct 16 ms 8440 KB Output is correct
33 Correct 16 ms 8440 KB Output is correct
34 Correct 15 ms 8480 KB Output is correct
35 Correct 16 ms 8440 KB Output is correct
36 Correct 16 ms 8568 KB Output is correct
37 Correct 16 ms 8440 KB Output is correct
38 Correct 15 ms 8440 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 8 ms 2040 KB Output is correct
4 Correct 9 ms 2040 KB Output is correct
5 Correct 8 ms 2168 KB Output is correct
6 Correct 10 ms 2168 KB Output is correct
7 Correct 9 ms 2168 KB Output is correct
8 Correct 10 ms 2168 KB Output is correct
9 Correct 9 ms 2168 KB Output is correct
10 Correct 9 ms 2172 KB Output is correct
11 Correct 7 ms 2040 KB Output is correct
12 Correct 7 ms 2040 KB Output is correct
13 Correct 7 ms 2068 KB Output is correct
14 Correct 7 ms 2040 KB Output is correct
15 Correct 7 ms 2040 KB Output is correct
16 Correct 6 ms 1528 KB Output is correct
17 Correct 5 ms 1400 KB Output is correct
18 Correct 5 ms 1272 KB Output is correct
19 Correct 5 ms 1400 KB Output is correct
20 Correct 5 ms 1400 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 14 ms 8440 KB Output is correct
4 Correct 14 ms 8568 KB Output is correct
5 Correct 15 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 14 ms 8440 KB Output is correct
9 Correct 14 ms 8440 KB Output is correct
10 Correct 14 ms 8440 KB Output is correct
11 Correct 14 ms 8440 KB Output is correct
12 Correct 14 ms 8440 KB Output is correct
13 Correct 14 ms 8440 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 1784 KB Output is correct
17 Correct 5 ms 1912 KB Output is correct
18 Correct 5 ms 1784 KB Output is correct
19 Correct 5 ms 1912 KB Output is correct
20 Correct 6 ms 1912 KB Output is correct
21 Correct 375 ms 10332 KB Output is correct
22 Correct 367 ms 10284 KB Output is correct
23 Correct 335 ms 9976 KB Output is correct
24 Correct 359 ms 10168 KB Output is correct
25 Correct 377 ms 10360 KB Output is correct
26 Correct 608 ms 10952 KB Output is correct
27 Correct 618 ms 11128 KB Output is correct
28 Correct 600 ms 11000 KB Output is correct
29 Correct 596 ms 10844 KB Output is correct
30 Correct 15 ms 8444 KB Output is correct
31 Correct 15 ms 8440 KB Output is correct
32 Correct 16 ms 8440 KB Output is correct
33 Correct 16 ms 8440 KB Output is correct
34 Correct 15 ms 8480 KB Output is correct
35 Correct 16 ms 8440 KB Output is correct
36 Correct 16 ms 8568 KB Output is correct
37 Correct 16 ms 8440 KB Output is correct
38 Correct 15 ms 8440 KB Output is correct
39 Correct 7 ms 2168 KB Output is correct
40 Correct 6 ms 2040 KB Output is correct
41 Correct 8 ms 2040 KB Output is correct
42 Correct 9 ms 2040 KB Output is correct
43 Correct 8 ms 2168 KB Output is correct
44 Correct 10 ms 2168 KB Output is correct
45 Correct 9 ms 2168 KB Output is correct
46 Correct 10 ms 2168 KB Output is correct
47 Correct 9 ms 2168 KB Output is correct
48 Correct 9 ms 2172 KB Output is correct
49 Correct 7 ms 2040 KB Output is correct
50 Correct 7 ms 2040 KB Output is correct
51 Correct 7 ms 2068 KB Output is correct
52 Correct 7 ms 2040 KB Output is correct
53 Correct 7 ms 2040 KB Output is correct
54 Correct 6 ms 1528 KB Output is correct
55 Correct 5 ms 1400 KB Output is correct
56 Correct 5 ms 1272 KB Output is correct
57 Correct 5 ms 1400 KB Output is correct
58 Correct 5 ms 1400 KB Output is correct
59 Correct 408 ms 11240 KB Output is correct
60 Correct 380 ms 10936 KB Output is correct
61 Correct 375 ms 11000 KB Output is correct
62 Correct 413 ms 11228 KB Output is correct
63 Correct 474 ms 11100 KB Output is correct
64 Correct 687 ms 12404 KB Output is correct
65 Correct 688 ms 12536 KB Output is correct
66 Correct 686 ms 12272 KB Output is correct
67 Correct 685 ms 12416 KB Output is correct
68 Correct 691 ms 12408 KB Output is correct
69 Correct 409 ms 11040 KB Output is correct
70 Correct 442 ms 11116 KB Output is correct
71 Correct 429 ms 11064 KB Output is correct
72 Correct 440 ms 11000 KB Output is correct
73 Correct 436 ms 11128 KB Output is correct
74 Correct 78 ms 2296 KB Output is correct
75 Correct 79 ms 2424 KB Output is correct
76 Correct 79 ms 2296 KB Output is correct
77 Correct 81 ms 2296 KB Output is correct
78 Correct 79 ms 2424 KB Output is correct