Submission #26408

# Submission time Handle Problem Language Result Execution time Memory
26408 2017-06-30T04:26:34 Z zscoder Boat (APIO16_boat) C++14
100 / 100
959 ms 4164 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 1e9 + 7;

int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

const int N = 501;

int dp[N+1][2*N+1];
vi x;
int l[2*N+1];
int a[N+1];
int b[N+1];
int inv[N*3+1];

ll modpow(ll a, ll b)
{
	ll r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		x.pb(a[i]);
		x.pb(b[i]+1);
	}
	for(int i=1;i<=N*3;i++) inv[i]=modpow(i,MOD-2);
	sort(x.begin(),x.end());
	x.erase(unique(x.begin(),x.end()),x.end());
	for(int i=0;i<x.size();i++)
	{
		if(i==0) l[i]=x[i];
		else l[i]=x[i]-x[i-1];
	}
	for(int i=1;i<=n;i++)
	{
		a[i]=upper_bound(x.begin(),x.end(),a[i])-x.begin();
		b[i]=upper_bound(x.begin(),x.end(),b[i])-x.begin();
	}
	for(int i=0;i<x.size();i++) dp[0][i]=1;
	for(int i=1;i<=n;i++)
	{
		//cerr<<i<<' '<<a[i]<<' '<<b[i]<<'\n';
		for(int j=a[i];j<=b[i];j++)
		{
			dp[i][j]=add(dp[i][j],mult(dp[i-1][j-1],l[j]));
			int cur=l[j]-1; int cnt=1;
			for(int k=i-1;k>0;k--)
			{
				if(a[k]<=j&&j<=b[k])
				{
					cur=mult(cur,l[j]+cnt-1);
					cur=mult(cur,inv[++cnt]);
					dp[i][j]=add(dp[i][j],mult(dp[k-1][j-1],cur));
				}
			}
		}
		dp[i][0]=1;
		for(int j=1;j<x.size();j++)
		{
			dp[i][j]=add(dp[i][j],dp[i-1][j]);
			dp[i][j]=add(dp[i][j],dp[i][j-1]);
			dp[i][j]=add(dp[i][j],MOD-dp[i-1][j-1]);
		}
	}
	int ans=dp[n][int(x.size())-1];
	ans=add(ans,MOD-1);
	cout<<ans<<'\n';
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:72:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<x.size();i++)
               ^
boat.cpp:82:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<x.size();i++) dp[0][i]=1;
               ^
boat.cpp:101:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=1;j<x.size();j++)
                ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4164 KB Output is correct
2 Correct 3 ms 4164 KB Output is correct
3 Correct 3 ms 4164 KB Output is correct
4 Correct 3 ms 4164 KB Output is correct
5 Correct 6 ms 4164 KB Output is correct
6 Correct 6 ms 4164 KB Output is correct
7 Correct 6 ms 4164 KB Output is correct
8 Correct 3 ms 4164 KB Output is correct
9 Correct 3 ms 4164 KB Output is correct
10 Correct 0 ms 4164 KB Output is correct
11 Correct 0 ms 4164 KB Output is correct
12 Correct 3 ms 4164 KB Output is correct
13 Correct 3 ms 4164 KB Output is correct
14 Correct 3 ms 4164 KB Output is correct
15 Correct 0 ms 4164 KB Output is correct
16 Correct 0 ms 4164 KB Output is correct
17 Correct 3 ms 4164 KB Output is correct
18 Correct 3 ms 4164 KB Output is correct
19 Correct 3 ms 4164 KB Output is correct
20 Correct 0 ms 4164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4164 KB Output is correct
2 Correct 3 ms 4164 KB Output is correct
3 Correct 3 ms 4164 KB Output is correct
4 Correct 3 ms 4164 KB Output is correct
5 Correct 6 ms 4164 KB Output is correct
6 Correct 6 ms 4164 KB Output is correct
7 Correct 6 ms 4164 KB Output is correct
8 Correct 3 ms 4164 KB Output is correct
9 Correct 3 ms 4164 KB Output is correct
10 Correct 0 ms 4164 KB Output is correct
11 Correct 0 ms 4164 KB Output is correct
12 Correct 3 ms 4164 KB Output is correct
13 Correct 3 ms 4164 KB Output is correct
14 Correct 3 ms 4164 KB Output is correct
15 Correct 0 ms 4164 KB Output is correct
16 Correct 0 ms 4164 KB Output is correct
17 Correct 3 ms 4164 KB Output is correct
18 Correct 3 ms 4164 KB Output is correct
19 Correct 3 ms 4164 KB Output is correct
20 Correct 0 ms 4164 KB Output is correct
21 Correct 529 ms 4164 KB Output is correct
22 Correct 449 ms 4164 KB Output is correct
23 Correct 416 ms 4164 KB Output is correct
24 Correct 513 ms 4164 KB Output is correct
25 Correct 486 ms 4164 KB Output is correct
26 Correct 756 ms 4164 KB Output is correct
27 Correct 769 ms 4164 KB Output is correct
28 Correct 763 ms 4164 KB Output is correct
29 Correct 756 ms 4164 KB Output is correct
30 Correct 3 ms 4164 KB Output is correct
31 Correct 3 ms 4164 KB Output is correct
32 Correct 6 ms 4164 KB Output is correct
33 Correct 6 ms 4164 KB Output is correct
34 Correct 6 ms 4164 KB Output is correct
35 Correct 6 ms 4164 KB Output is correct
36 Correct 3 ms 4164 KB Output is correct
37 Correct 6 ms 4164 KB Output is correct
38 Correct 6 ms 4164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4164 KB Output is correct
2 Correct 3 ms 4164 KB Output is correct
3 Correct 3 ms 4164 KB Output is correct
4 Correct 3 ms 4164 KB Output is correct
5 Correct 3 ms 4164 KB Output is correct
6 Correct 6 ms 4164 KB Output is correct
7 Correct 6 ms 4164 KB Output is correct
8 Correct 3 ms 4164 KB Output is correct
9 Correct 6 ms 4164 KB Output is correct
10 Correct 6 ms 4164 KB Output is correct
11 Correct 3 ms 4164 KB Output is correct
12 Correct 3 ms 4164 KB Output is correct
13 Correct 3 ms 4164 KB Output is correct
14 Correct 3 ms 4164 KB Output is correct
15 Correct 3 ms 4164 KB Output is correct
16 Correct 3 ms 4164 KB Output is correct
17 Correct 3 ms 4164 KB Output is correct
18 Correct 3 ms 4164 KB Output is correct
19 Correct 3 ms 4164 KB Output is correct
20 Correct 3 ms 4164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4164 KB Output is correct
2 Correct 3 ms 4164 KB Output is correct
3 Correct 3 ms 4164 KB Output is correct
4 Correct 3 ms 4164 KB Output is correct
5 Correct 6 ms 4164 KB Output is correct
6 Correct 6 ms 4164 KB Output is correct
7 Correct 6 ms 4164 KB Output is correct
8 Correct 3 ms 4164 KB Output is correct
9 Correct 3 ms 4164 KB Output is correct
10 Correct 0 ms 4164 KB Output is correct
11 Correct 0 ms 4164 KB Output is correct
12 Correct 3 ms 4164 KB Output is correct
13 Correct 3 ms 4164 KB Output is correct
14 Correct 3 ms 4164 KB Output is correct
15 Correct 0 ms 4164 KB Output is correct
16 Correct 0 ms 4164 KB Output is correct
17 Correct 3 ms 4164 KB Output is correct
18 Correct 3 ms 4164 KB Output is correct
19 Correct 3 ms 4164 KB Output is correct
20 Correct 0 ms 4164 KB Output is correct
21 Correct 529 ms 4164 KB Output is correct
22 Correct 449 ms 4164 KB Output is correct
23 Correct 416 ms 4164 KB Output is correct
24 Correct 513 ms 4164 KB Output is correct
25 Correct 486 ms 4164 KB Output is correct
26 Correct 756 ms 4164 KB Output is correct
27 Correct 769 ms 4164 KB Output is correct
28 Correct 763 ms 4164 KB Output is correct
29 Correct 756 ms 4164 KB Output is correct
30 Correct 3 ms 4164 KB Output is correct
31 Correct 3 ms 4164 KB Output is correct
32 Correct 6 ms 4164 KB Output is correct
33 Correct 6 ms 4164 KB Output is correct
34 Correct 6 ms 4164 KB Output is correct
35 Correct 6 ms 4164 KB Output is correct
36 Correct 3 ms 4164 KB Output is correct
37 Correct 6 ms 4164 KB Output is correct
38 Correct 6 ms 4164 KB Output is correct
39 Correct 3 ms 4164 KB Output is correct
40 Correct 3 ms 4164 KB Output is correct
41 Correct 3 ms 4164 KB Output is correct
42 Correct 3 ms 4164 KB Output is correct
43 Correct 3 ms 4164 KB Output is correct
44 Correct 6 ms 4164 KB Output is correct
45 Correct 6 ms 4164 KB Output is correct
46 Correct 3 ms 4164 KB Output is correct
47 Correct 6 ms 4164 KB Output is correct
48 Correct 6 ms 4164 KB Output is correct
49 Correct 3 ms 4164 KB Output is correct
50 Correct 3 ms 4164 KB Output is correct
51 Correct 3 ms 4164 KB Output is correct
52 Correct 3 ms 4164 KB Output is correct
53 Correct 3 ms 4164 KB Output is correct
54 Correct 3 ms 4164 KB Output is correct
55 Correct 3 ms 4164 KB Output is correct
56 Correct 3 ms 4164 KB Output is correct
57 Correct 3 ms 4164 KB Output is correct
58 Correct 3 ms 4164 KB Output is correct
59 Correct 523 ms 4164 KB Output is correct
60 Correct 536 ms 4164 KB Output is correct
61 Correct 479 ms 4164 KB Output is correct
62 Correct 539 ms 4164 KB Output is correct
63 Correct 569 ms 4164 KB Output is correct
64 Correct 886 ms 4164 KB Output is correct
65 Correct 883 ms 4164 KB Output is correct
66 Correct 936 ms 4164 KB Output is correct
67 Correct 959 ms 4164 KB Output is correct
68 Correct 933 ms 4164 KB Output is correct
69 Correct 426 ms 4164 KB Output is correct
70 Correct 429 ms 4164 KB Output is correct
71 Correct 429 ms 4164 KB Output is correct
72 Correct 459 ms 4164 KB Output is correct
73 Correct 466 ms 4164 KB Output is correct
74 Correct 99 ms 4164 KB Output is correct
75 Correct 93 ms 4164 KB Output is correct
76 Correct 96 ms 4164 KB Output is correct
77 Correct 99 ms 4164 KB Output is correct
78 Correct 96 ms 4164 KB Output is correct