답안 #372828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372828 2021-03-01T21:25:56 Z ogibogi2004 Boat (APIO16_boat) C++14
100 / 100
816 ms 6636 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const ll MAXN=1024;
ll dp[MAXN][2*MAXN];
ll l1[2*MAXN],r1[2*MAXN];
ll n;
ll a[MAXN],b[MAXN];
ll a1[MAXN],b1[MAXN];
ll inv[MAXN];
ll fastpow(ll x,ll p)
{
	if(p==0)return 1;
	ll t=fastpow(x,p/2);
	t*=t;t%=mod;
	if(p%2==1)t*=x;
	t%=mod;
	return t;
}
int main()
{
	cin>>n;
	vector<ll>v;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		v.push_back(a[i]);
		v.push_back(b[i]+1);
	}
	sort(v.begin(),v.end());
	int cnt=0;
	for(int i=1;i<v.size();i++)
	{
		if(v[i]==v[i-1])continue;
		cnt++;
		l1[cnt]=v[i-1];
		r1[cnt]=v[i]-1;
	}
	for(int i=0;i<2*MAXN;i++)
	{
		dp[0][i]=1;
	}
	for(int i=1;i<MAXN;i++)inv[i]=fastpow(i,mod-2);
	for(int i=1;i<=cnt;i++)
	{
		ll t=r1[i]-l1[i]+1;
		for(int j=1;j<=n;j++)
		{
			dp[j][i]=dp[j][i-1];
			if(a[j]>r1[i]||b[j]<l1[i])continue;
			ll fnaf=t,c=1;
			for(int k=j-1;k>=0;k--)
			{
				dp[j][i]=dp[j][i]+dp[k][i-1]*fnaf;
				dp[j][i]%=mod;
				if(a[k]<=l1[i]&&b[k]>=r1[i])
				{
					fnaf=fnaf*(t+c);
					fnaf%=mod;
					c++;
					fnaf*=inv[c];
					fnaf%=mod;
				}
			}
		}
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ans+=dp[i][cnt];ans%=mod;
	}
	cout<<ans<<endl;
return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for(int i=1;i<v.size();i++)
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6380 KB Output is correct
2 Correct 10 ms 6380 KB Output is correct
3 Correct 10 ms 6380 KB Output is correct
4 Correct 10 ms 6380 KB Output is correct
5 Correct 10 ms 6380 KB Output is correct
6 Correct 10 ms 6380 KB Output is correct
7 Correct 10 ms 6380 KB Output is correct
8 Correct 10 ms 6380 KB Output is correct
9 Correct 10 ms 6380 KB Output is correct
10 Correct 11 ms 6380 KB Output is correct
11 Correct 10 ms 6380 KB Output is correct
12 Correct 10 ms 6400 KB Output is correct
13 Correct 10 ms 6392 KB Output is correct
14 Correct 10 ms 6380 KB Output is correct
15 Correct 10 ms 6380 KB Output is correct
16 Correct 5 ms 2412 KB Output is correct
17 Correct 5 ms 2412 KB Output is correct
18 Correct 6 ms 2412 KB Output is correct
19 Correct 5 ms 2412 KB Output is correct
20 Correct 5 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6380 KB Output is correct
2 Correct 10 ms 6380 KB Output is correct
3 Correct 10 ms 6380 KB Output is correct
4 Correct 10 ms 6380 KB Output is correct
5 Correct 10 ms 6380 KB Output is correct
6 Correct 10 ms 6380 KB Output is correct
7 Correct 10 ms 6380 KB Output is correct
8 Correct 10 ms 6380 KB Output is correct
9 Correct 10 ms 6380 KB Output is correct
10 Correct 11 ms 6380 KB Output is correct
11 Correct 10 ms 6380 KB Output is correct
12 Correct 10 ms 6400 KB Output is correct
13 Correct 10 ms 6392 KB Output is correct
14 Correct 10 ms 6380 KB Output is correct
15 Correct 10 ms 6380 KB Output is correct
16 Correct 5 ms 2412 KB Output is correct
17 Correct 5 ms 2412 KB Output is correct
18 Correct 6 ms 2412 KB Output is correct
19 Correct 5 ms 2412 KB Output is correct
20 Correct 5 ms 2412 KB Output is correct
21 Correct 473 ms 6440 KB Output is correct
22 Correct 412 ms 6380 KB Output is correct
23 Correct 377 ms 6508 KB Output is correct
24 Correct 408 ms 6380 KB Output is correct
25 Correct 403 ms 6380 KB Output is correct
26 Correct 720 ms 6508 KB Output is correct
27 Correct 726 ms 6380 KB Output is correct
28 Correct 695 ms 6400 KB Output is correct
29 Correct 695 ms 6508 KB Output is correct
30 Correct 12 ms 6508 KB Output is correct
31 Correct 13 ms 6380 KB Output is correct
32 Correct 14 ms 6380 KB Output is correct
33 Correct 12 ms 6380 KB Output is correct
34 Correct 13 ms 6380 KB Output is correct
35 Correct 13 ms 6412 KB Output is correct
36 Correct 13 ms 6380 KB Output is correct
37 Correct 12 ms 6380 KB Output is correct
38 Correct 13 ms 6380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Correct 4 ms 748 KB Output is correct
5 Correct 4 ms 748 KB Output is correct
6 Correct 6 ms 748 KB Output is correct
7 Correct 6 ms 748 KB Output is correct
8 Correct 6 ms 748 KB Output is correct
9 Correct 6 ms 748 KB Output is correct
10 Correct 6 ms 748 KB Output is correct
11 Correct 4 ms 748 KB Output is correct
12 Correct 3 ms 876 KB Output is correct
13 Correct 4 ms 896 KB Output is correct
14 Correct 3 ms 764 KB Output is correct
15 Correct 4 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6380 KB Output is correct
2 Correct 10 ms 6380 KB Output is correct
3 Correct 10 ms 6380 KB Output is correct
4 Correct 10 ms 6380 KB Output is correct
5 Correct 10 ms 6380 KB Output is correct
6 Correct 10 ms 6380 KB Output is correct
7 Correct 10 ms 6380 KB Output is correct
8 Correct 10 ms 6380 KB Output is correct
9 Correct 10 ms 6380 KB Output is correct
10 Correct 11 ms 6380 KB Output is correct
11 Correct 10 ms 6380 KB Output is correct
12 Correct 10 ms 6400 KB Output is correct
13 Correct 10 ms 6392 KB Output is correct
14 Correct 10 ms 6380 KB Output is correct
15 Correct 10 ms 6380 KB Output is correct
16 Correct 5 ms 2412 KB Output is correct
17 Correct 5 ms 2412 KB Output is correct
18 Correct 6 ms 2412 KB Output is correct
19 Correct 5 ms 2412 KB Output is correct
20 Correct 5 ms 2412 KB Output is correct
21 Correct 473 ms 6440 KB Output is correct
22 Correct 412 ms 6380 KB Output is correct
23 Correct 377 ms 6508 KB Output is correct
24 Correct 408 ms 6380 KB Output is correct
25 Correct 403 ms 6380 KB Output is correct
26 Correct 720 ms 6508 KB Output is correct
27 Correct 726 ms 6380 KB Output is correct
28 Correct 695 ms 6400 KB Output is correct
29 Correct 695 ms 6508 KB Output is correct
30 Correct 12 ms 6508 KB Output is correct
31 Correct 13 ms 6380 KB Output is correct
32 Correct 14 ms 6380 KB Output is correct
33 Correct 12 ms 6380 KB Output is correct
34 Correct 13 ms 6380 KB Output is correct
35 Correct 13 ms 6412 KB Output is correct
36 Correct 13 ms 6380 KB Output is correct
37 Correct 12 ms 6380 KB Output is correct
38 Correct 13 ms 6380 KB Output is correct
39 Correct 3 ms 748 KB Output is correct
40 Correct 3 ms 748 KB Output is correct
41 Correct 3 ms 748 KB Output is correct
42 Correct 4 ms 748 KB Output is correct
43 Correct 4 ms 748 KB Output is correct
44 Correct 6 ms 748 KB Output is correct
45 Correct 6 ms 748 KB Output is correct
46 Correct 6 ms 748 KB Output is correct
47 Correct 6 ms 748 KB Output is correct
48 Correct 6 ms 748 KB Output is correct
49 Correct 4 ms 748 KB Output is correct
50 Correct 3 ms 876 KB Output is correct
51 Correct 4 ms 896 KB Output is correct
52 Correct 3 ms 764 KB Output is correct
53 Correct 4 ms 748 KB Output is correct
54 Correct 3 ms 748 KB Output is correct
55 Correct 3 ms 748 KB Output is correct
56 Correct 3 ms 748 KB Output is correct
57 Correct 3 ms 748 KB Output is correct
58 Correct 3 ms 748 KB Output is correct
59 Correct 453 ms 6508 KB Output is correct
60 Correct 458 ms 6508 KB Output is correct
61 Correct 399 ms 6380 KB Output is correct
62 Correct 471 ms 6508 KB Output is correct
63 Correct 478 ms 6508 KB Output is correct
64 Correct 803 ms 6380 KB Output is correct
65 Correct 816 ms 6612 KB Output is correct
66 Correct 798 ms 6508 KB Output is correct
67 Correct 810 ms 6404 KB Output is correct
68 Correct 802 ms 6636 KB Output is correct
69 Correct 342 ms 6508 KB Output is correct
70 Correct 326 ms 6380 KB Output is correct
71 Correct 331 ms 6508 KB Output is correct
72 Correct 347 ms 6508 KB Output is correct
73 Correct 352 ms 6380 KB Output is correct
74 Correct 90 ms 2412 KB Output is correct
75 Correct 99 ms 2412 KB Output is correct
76 Correct 94 ms 2412 KB Output is correct
77 Correct 89 ms 2412 KB Output is correct
78 Correct 105 ms 2412 KB Output is correct