Submission #754822

# Submission time Handle Problem Language Result Execution time Memory
754822 2023-06-08T16:50:23 Z denniskim Boat (APIO16_boat) C++17
100 / 100
1823 ms 16408 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

ll n;
pll a[1010];
ll ss = 1000000007;
ll inv[1010];
vector<ll> zip;
ll dp[1010][1010];
ll sum[1010][1010];
ll LC[1010];
ll xjc[1010];

ll sqrmtp(ll X, ll Y)
{
	ll ret = 1;
	
	while(Y)
	{
		if(Y & 1)
			ret = ret * X % ss;
		
		X = X * X % ss;
		Y >>= 1;
	}
	
	return ret;
}

int main(void)
{
	fastio
	
	cin >> n;
	
	for(ll i = 1 ; i <= n ; i++)
	{
		cin >> a[i].fi >> a[i].se;
		
		zip.push_back(a[i].fi);
		zip.push_back(a[i].se + 1);
	}
	
	for(ll i = 1 ; i <= n ; i++)
		inv[i] = sqrmtp(i, ss - 2);
	
	compress(zip);
	
	dp[0][0] = 1;
	sum[0][0] = 1;
	
	for(ll i = 1 ; i <= n ; i++)
		sum[0][i] = 1;
	
	ll siz = (ll)zip.size();
	
	for(ll i = 1 ; i < siz ; i++)
	{
		vector<ll> num;
		
		for(ll j = 1 ; j <= n ; j++)
		{
			if(a[j].fi <= zip[i - 1] && zip[i] - 1 <= a[j].se)
				num.push_back(j);
		}
		
		ll L = zip[i] - zip[i - 1];
		LC[0] = 1;
		
		for(ll j = 1 ; j <= n ; j++)
		{
			if(L <= 0)
				break;
			
			LC[j] = LC[j - 1] * L % ss * inv[j] % ss;
			L--;
		}
		
		L = zip[i] - zip[i - 1];
		
		ll siz2 = (ll)num.size();
		
		for(ll j = 0 ; j <= siz2 ; j++)
		{
			ll gap = j;
			ll gap2 = 1;
			
			xjc[j] = 0;
			
			if(L <= 1)
				continue;
			
			xjc[j] = LC[2];
			
			for(ll k = 1 ; ; k++)
			{
				if(k + 2 > L || k > j)
					break;
				
				gap2 = gap2 * gap % ss * inv[k] % ss;
				gap--;
				xjc[j] = (xjc[j] + gap2 * LC[k + 2] % ss) % ss;
			}
		}
		
		for(ll j = 0 ; j < siz2 ; j++)
		{
			dp[i][num[j]] = (dp[i][num[j]] + sum[i - 1][num[j] - 1] * LC[1] % ss) % ss;
			
			if(L >= 2)
			{
				for(ll k = 0 ; k < j ; k++)
					dp[i][num[j]] = (dp[i][num[j]] + sum[i - 1][num[k] - 1] * xjc[j - k - 1] % ss) % ss;
			}
		}
		
		for(ll j = 0 ; j <= n ; j++)
			dp[i][j] = (dp[i][j] + dp[i - 1][j]) % ss;
		
		sum[i][0] = dp[i][0];
		
		for(ll j = 1 ; j <= n ; j++)
			sum[i][j] = (sum[i][j - 1] + dp[i][j]) % ss;
	}
	
	sum[siz - 1][n]--;
	sum[siz - 1][n] = (sum[siz - 1][n] % ss + ss) % ss;
	
	cout << sum[siz - 1][n];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 16084 KB Output is correct
2 Correct 20 ms 16168 KB Output is correct
3 Correct 20 ms 16084 KB Output is correct
4 Correct 20 ms 16136 KB Output is correct
5 Correct 20 ms 16100 KB Output is correct
6 Correct 20 ms 16192 KB Output is correct
7 Correct 21 ms 16076 KB Output is correct
8 Correct 20 ms 16084 KB Output is correct
9 Correct 19 ms 16076 KB Output is correct
10 Correct 19 ms 16084 KB Output is correct
11 Correct 20 ms 16108 KB Output is correct
12 Correct 19 ms 16096 KB Output is correct
13 Correct 19 ms 16084 KB Output is correct
14 Correct 20 ms 16188 KB Output is correct
15 Correct 20 ms 16088 KB Output is correct
16 Correct 4 ms 3156 KB Output is correct
17 Correct 5 ms 3288 KB Output is correct
18 Correct 4 ms 3160 KB Output is correct
19 Correct 5 ms 3284 KB Output is correct
20 Correct 4 ms 3284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 16084 KB Output is correct
2 Correct 20 ms 16168 KB Output is correct
3 Correct 20 ms 16084 KB Output is correct
4 Correct 20 ms 16136 KB Output is correct
5 Correct 20 ms 16100 KB Output is correct
6 Correct 20 ms 16192 KB Output is correct
7 Correct 21 ms 16076 KB Output is correct
8 Correct 20 ms 16084 KB Output is correct
9 Correct 19 ms 16076 KB Output is correct
10 Correct 19 ms 16084 KB Output is correct
11 Correct 20 ms 16108 KB Output is correct
12 Correct 19 ms 16096 KB Output is correct
13 Correct 19 ms 16084 KB Output is correct
14 Correct 20 ms 16188 KB Output is correct
15 Correct 20 ms 16088 KB Output is correct
16 Correct 4 ms 3156 KB Output is correct
17 Correct 5 ms 3288 KB Output is correct
18 Correct 4 ms 3160 KB Output is correct
19 Correct 5 ms 3284 KB Output is correct
20 Correct 4 ms 3284 KB Output is correct
21 Correct 188 ms 14668 KB Output is correct
22 Correct 187 ms 14912 KB Output is correct
23 Correct 159 ms 14616 KB Output is correct
24 Correct 184 ms 14516 KB Output is correct
25 Correct 181 ms 14536 KB Output is correct
26 Correct 340 ms 14312 KB Output is correct
27 Correct 370 ms 14408 KB Output is correct
28 Correct 353 ms 14168 KB Output is correct
29 Correct 363 ms 14152 KB Output is correct
30 Correct 19 ms 16084 KB Output is correct
31 Correct 20 ms 16172 KB Output is correct
32 Correct 18 ms 16076 KB Output is correct
33 Correct 19 ms 16180 KB Output is correct
34 Correct 19 ms 16060 KB Output is correct
35 Correct 19 ms 16100 KB Output is correct
36 Correct 19 ms 16084 KB Output is correct
37 Correct 19 ms 16084 KB Output is correct
38 Correct 19 ms 16060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2132 KB Output is correct
2 Correct 6 ms 2256 KB Output is correct
3 Correct 7 ms 2132 KB Output is correct
4 Correct 7 ms 2256 KB Output is correct
5 Correct 8 ms 2260 KB Output is correct
6 Correct 15 ms 2260 KB Output is correct
7 Correct 16 ms 2132 KB Output is correct
8 Correct 15 ms 2256 KB Output is correct
9 Correct 15 ms 2188 KB Output is correct
10 Correct 15 ms 2260 KB Output is correct
11 Correct 8 ms 2260 KB Output is correct
12 Correct 6 ms 2132 KB Output is correct
13 Correct 7 ms 2260 KB Output is correct
14 Correct 7 ms 2256 KB Output is correct
15 Correct 8 ms 2156 KB Output is correct
16 Correct 4 ms 1364 KB Output is correct
17 Correct 4 ms 1356 KB Output is correct
18 Correct 4 ms 1364 KB Output is correct
19 Correct 4 ms 1364 KB Output is correct
20 Correct 5 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 16084 KB Output is correct
2 Correct 20 ms 16168 KB Output is correct
3 Correct 20 ms 16084 KB Output is correct
4 Correct 20 ms 16136 KB Output is correct
5 Correct 20 ms 16100 KB Output is correct
6 Correct 20 ms 16192 KB Output is correct
7 Correct 21 ms 16076 KB Output is correct
8 Correct 20 ms 16084 KB Output is correct
9 Correct 19 ms 16076 KB Output is correct
10 Correct 19 ms 16084 KB Output is correct
11 Correct 20 ms 16108 KB Output is correct
12 Correct 19 ms 16096 KB Output is correct
13 Correct 19 ms 16084 KB Output is correct
14 Correct 20 ms 16188 KB Output is correct
15 Correct 20 ms 16088 KB Output is correct
16 Correct 4 ms 3156 KB Output is correct
17 Correct 5 ms 3288 KB Output is correct
18 Correct 4 ms 3160 KB Output is correct
19 Correct 5 ms 3284 KB Output is correct
20 Correct 4 ms 3284 KB Output is correct
21 Correct 188 ms 14668 KB Output is correct
22 Correct 187 ms 14912 KB Output is correct
23 Correct 159 ms 14616 KB Output is correct
24 Correct 184 ms 14516 KB Output is correct
25 Correct 181 ms 14536 KB Output is correct
26 Correct 340 ms 14312 KB Output is correct
27 Correct 370 ms 14408 KB Output is correct
28 Correct 353 ms 14168 KB Output is correct
29 Correct 363 ms 14152 KB Output is correct
30 Correct 19 ms 16084 KB Output is correct
31 Correct 20 ms 16172 KB Output is correct
32 Correct 18 ms 16076 KB Output is correct
33 Correct 19 ms 16180 KB Output is correct
34 Correct 19 ms 16060 KB Output is correct
35 Correct 19 ms 16100 KB Output is correct
36 Correct 19 ms 16084 KB Output is correct
37 Correct 19 ms 16084 KB Output is correct
38 Correct 19 ms 16060 KB Output is correct
39 Correct 8 ms 2132 KB Output is correct
40 Correct 6 ms 2256 KB Output is correct
41 Correct 7 ms 2132 KB Output is correct
42 Correct 7 ms 2256 KB Output is correct
43 Correct 8 ms 2260 KB Output is correct
44 Correct 15 ms 2260 KB Output is correct
45 Correct 16 ms 2132 KB Output is correct
46 Correct 15 ms 2256 KB Output is correct
47 Correct 15 ms 2188 KB Output is correct
48 Correct 15 ms 2260 KB Output is correct
49 Correct 8 ms 2260 KB Output is correct
50 Correct 6 ms 2132 KB Output is correct
51 Correct 7 ms 2260 KB Output is correct
52 Correct 7 ms 2256 KB Output is correct
53 Correct 8 ms 2156 KB Output is correct
54 Correct 4 ms 1364 KB Output is correct
55 Correct 4 ms 1356 KB Output is correct
56 Correct 4 ms 1364 KB Output is correct
57 Correct 4 ms 1364 KB Output is correct
58 Correct 5 ms 1364 KB Output is correct
59 Correct 772 ms 16408 KB Output is correct
60 Correct 685 ms 16124 KB Output is correct
61 Correct 665 ms 16160 KB Output is correct
62 Correct 788 ms 16160 KB Output is correct
63 Correct 737 ms 16152 KB Output is correct
64 Correct 1802 ms 16208 KB Output is correct
65 Correct 1806 ms 16144 KB Output is correct
66 Correct 1816 ms 16184 KB Output is correct
67 Correct 1767 ms 16160 KB Output is correct
68 Correct 1823 ms 16260 KB Output is correct
69 Correct 679 ms 16128 KB Output is correct
70 Correct 671 ms 16156 KB Output is correct
71 Correct 697 ms 16064 KB Output is correct
72 Correct 739 ms 16156 KB Output is correct
73 Correct 704 ms 16180 KB Output is correct
74 Correct 81 ms 3144 KB Output is correct
75 Correct 71 ms 3216 KB Output is correct
76 Correct 78 ms 3188 KB Output is correct
77 Correct 86 ms 3236 KB Output is correct
78 Correct 84 ms 3096 KB Output is correct