답안 #372827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372827 2021-03-01T21:21:22 Z ogibogi2004 Boat (APIO16_boat) C++14
9 / 100
538 ms 6528 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[j]<=l1[i]&&b[j]>=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 11 ms 6380 KB Output is correct
2 Correct 11 ms 6380 KB Output is correct
3 Correct 11 ms 6380 KB Output is correct
4 Correct 11 ms 6380 KB Output is correct
5 Correct 13 ms 6380 KB Output is correct
6 Correct 11 ms 6380 KB Output is correct
7 Correct 12 ms 6380 KB Output is correct
8 Correct 11 ms 6380 KB Output is correct
9 Correct 12 ms 6380 KB Output is correct
10 Correct 11 ms 6380 KB Output is correct
11 Correct 11 ms 6400 KB Output is correct
12 Correct 11 ms 6400 KB Output is correct
13 Correct 11 ms 6380 KB Output is correct
14 Correct 11 ms 6380 KB Output is correct
15 Correct 11 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 5 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 11 ms 6380 KB Output is correct
2 Correct 11 ms 6380 KB Output is correct
3 Correct 11 ms 6380 KB Output is correct
4 Correct 11 ms 6380 KB Output is correct
5 Correct 13 ms 6380 KB Output is correct
6 Correct 11 ms 6380 KB Output is correct
7 Correct 12 ms 6380 KB Output is correct
8 Correct 11 ms 6380 KB Output is correct
9 Correct 12 ms 6380 KB Output is correct
10 Correct 11 ms 6380 KB Output is correct
11 Correct 11 ms 6400 KB Output is correct
12 Correct 11 ms 6400 KB Output is correct
13 Correct 11 ms 6380 KB Output is correct
14 Correct 11 ms 6380 KB Output is correct
15 Correct 11 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 5 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 Incorrect 538 ms 6528 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6380 KB Output is correct
2 Correct 11 ms 6380 KB Output is correct
3 Correct 11 ms 6380 KB Output is correct
4 Correct 11 ms 6380 KB Output is correct
5 Correct 13 ms 6380 KB Output is correct
6 Correct 11 ms 6380 KB Output is correct
7 Correct 12 ms 6380 KB Output is correct
8 Correct 11 ms 6380 KB Output is correct
9 Correct 12 ms 6380 KB Output is correct
10 Correct 11 ms 6380 KB Output is correct
11 Correct 11 ms 6400 KB Output is correct
12 Correct 11 ms 6400 KB Output is correct
13 Correct 11 ms 6380 KB Output is correct
14 Correct 11 ms 6380 KB Output is correct
15 Correct 11 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 5 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 Incorrect 538 ms 6528 KB Output isn't correct
22 Halted 0 ms 0 KB -