Submission #111381

# Submission time Handle Problem Language Result Execution time Memory
111381 2019-05-15T04:16:21 Z diamond_duke Boat (APIO16_boat) C++11
100 / 100
752 ms 4572 KB
#include <algorithm>
#include <cstring>
#include <cstdio>
using ll = long long;
constexpr int MOD = 1e9 + 7;
inline void Add(int &x, int y) { (x += y) >= MOD ? (x -= MOD) : 0; }
inline int quick_pow(int a, int n)
{
	int res = 1;
	while (n)
	{
		if (n & 1)
			res = (ll)res * a % MOD;
		a = (ll)a * a % MOD;
		n >>= 1;
	}
	return res;
}
int lp[505], rp[505], app[1005], dp[1005][505], sum[1005][505], inv[505];
int main()
{
	// freopen("uoj-204.in", "r", stdin);
	int n, cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", lp + i, rp + i);
		app[cnt++] = lp[i];
		app[cnt++] = ++rp[i];
	}
	std::sort(app, app + cnt);
	cnt = std::unique(app, app + cnt) - app;
	for (int i = 0; i < n; i++)
	{
		lp[i] = std::lower_bound(app, app + cnt, lp[i]) - app;
		rp[i] = std::lower_bound(app, app + cnt, rp[i]) - app;
	}
	inv[0] = inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < cnt; j++)
		{
			for (int k = 0; k <= i; k++)
			{
				sum[j + 1][k] = sum[j][k];
				Add(sum[j + 1][k], dp[j][k]);
			}
		}
		for (int j = lp[i]; j < rp[i]; j++)
		{
			int len = app[j + 1] - app[j], one = 0;
			for (int k = i; k >= 0; k--)
			{
				dp[j][k + 1] = (dp[j][k + 1] + (ll)dp[j][k] * (len - k) % MOD * inv[k + 1]) % MOD;
				Add(one, sum[j][k]);
			}
			dp[j][1] = (dp[j][1] + (ll)one * len) % MOD;
		}
	}
	int ans = MOD - 1;
	for (int i = 0; i < cnt; i++)
	{
		for (int j = 0; j <= n; j++)
			Add(ans, dp[i][j]);
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
boat.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", lp + i, rp + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 116 ms 4332 KB Output is correct
2 Correct 123 ms 4388 KB Output is correct
3 Correct 140 ms 4344 KB Output is correct
4 Correct 130 ms 4232 KB Output is correct
5 Correct 125 ms 4216 KB Output is correct
6 Correct 138 ms 4208 KB Output is correct
7 Correct 134 ms 4220 KB Output is correct
8 Correct 131 ms 4208 KB Output is correct
9 Correct 140 ms 4236 KB Output is correct
10 Correct 106 ms 4316 KB Output is correct
11 Correct 112 ms 4216 KB Output is correct
12 Correct 109 ms 4216 KB Output is correct
13 Correct 109 ms 4344 KB Output is correct
14 Correct 115 ms 4344 KB Output is correct
15 Correct 108 ms 4316 KB Output is correct
16 Correct 21 ms 1024 KB Output is correct
17 Correct 24 ms 1144 KB Output is correct
18 Correct 26 ms 1024 KB Output is correct
19 Correct 25 ms 1152 KB Output is correct
20 Correct 25 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 4332 KB Output is correct
2 Correct 123 ms 4388 KB Output is correct
3 Correct 140 ms 4344 KB Output is correct
4 Correct 130 ms 4232 KB Output is correct
5 Correct 125 ms 4216 KB Output is correct
6 Correct 138 ms 4208 KB Output is correct
7 Correct 134 ms 4220 KB Output is correct
8 Correct 131 ms 4208 KB Output is correct
9 Correct 140 ms 4236 KB Output is correct
10 Correct 106 ms 4316 KB Output is correct
11 Correct 112 ms 4216 KB Output is correct
12 Correct 109 ms 4216 KB Output is correct
13 Correct 109 ms 4344 KB Output is correct
14 Correct 115 ms 4344 KB Output is correct
15 Correct 108 ms 4316 KB Output is correct
16 Correct 21 ms 1024 KB Output is correct
17 Correct 24 ms 1144 KB Output is correct
18 Correct 26 ms 1024 KB Output is correct
19 Correct 25 ms 1152 KB Output is correct
20 Correct 25 ms 1144 KB Output is correct
21 Correct 349 ms 3968 KB Output is correct
22 Correct 274 ms 3968 KB Output is correct
23 Correct 286 ms 3960 KB Output is correct
24 Correct 320 ms 3840 KB Output is correct
25 Correct 342 ms 3960 KB Output is correct
26 Correct 331 ms 3732 KB Output is correct
27 Correct 347 ms 3832 KB Output is correct
28 Correct 399 ms 3832 KB Output is correct
29 Correct 459 ms 3804 KB Output is correct
30 Correct 135 ms 4416 KB Output is correct
31 Correct 125 ms 4324 KB Output is correct
32 Correct 126 ms 4216 KB Output is correct
33 Correct 143 ms 4352 KB Output is correct
34 Correct 128 ms 4252 KB Output is correct
35 Correct 138 ms 4216 KB Output is correct
36 Correct 128 ms 4240 KB Output is correct
37 Correct 145 ms 4252 KB Output is correct
38 Correct 110 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 7 ms 1152 KB Output is correct
3 Correct 7 ms 1280 KB Output is correct
4 Correct 8 ms 1152 KB Output is correct
5 Correct 11 ms 1152 KB Output is correct
6 Correct 9 ms 1152 KB Output is correct
7 Correct 9 ms 1152 KB Output is correct
8 Correct 11 ms 1152 KB Output is correct
9 Correct 11 ms 1152 KB Output is correct
10 Correct 8 ms 1152 KB Output is correct
11 Correct 6 ms 1152 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 7 ms 1152 KB Output is correct
14 Correct 8 ms 1152 KB Output is correct
15 Correct 9 ms 1152 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 4332 KB Output is correct
2 Correct 123 ms 4388 KB Output is correct
3 Correct 140 ms 4344 KB Output is correct
4 Correct 130 ms 4232 KB Output is correct
5 Correct 125 ms 4216 KB Output is correct
6 Correct 138 ms 4208 KB Output is correct
7 Correct 134 ms 4220 KB Output is correct
8 Correct 131 ms 4208 KB Output is correct
9 Correct 140 ms 4236 KB Output is correct
10 Correct 106 ms 4316 KB Output is correct
11 Correct 112 ms 4216 KB Output is correct
12 Correct 109 ms 4216 KB Output is correct
13 Correct 109 ms 4344 KB Output is correct
14 Correct 115 ms 4344 KB Output is correct
15 Correct 108 ms 4316 KB Output is correct
16 Correct 21 ms 1024 KB Output is correct
17 Correct 24 ms 1144 KB Output is correct
18 Correct 26 ms 1024 KB Output is correct
19 Correct 25 ms 1152 KB Output is correct
20 Correct 25 ms 1144 KB Output is correct
21 Correct 349 ms 3968 KB Output is correct
22 Correct 274 ms 3968 KB Output is correct
23 Correct 286 ms 3960 KB Output is correct
24 Correct 320 ms 3840 KB Output is correct
25 Correct 342 ms 3960 KB Output is correct
26 Correct 331 ms 3732 KB Output is correct
27 Correct 347 ms 3832 KB Output is correct
28 Correct 399 ms 3832 KB Output is correct
29 Correct 459 ms 3804 KB Output is correct
30 Correct 135 ms 4416 KB Output is correct
31 Correct 125 ms 4324 KB Output is correct
32 Correct 126 ms 4216 KB Output is correct
33 Correct 143 ms 4352 KB Output is correct
34 Correct 128 ms 4252 KB Output is correct
35 Correct 138 ms 4216 KB Output is correct
36 Correct 128 ms 4240 KB Output is correct
37 Correct 145 ms 4252 KB Output is correct
38 Correct 110 ms 4216 KB Output is correct
39 Correct 6 ms 1152 KB Output is correct
40 Correct 7 ms 1152 KB Output is correct
41 Correct 7 ms 1280 KB Output is correct
42 Correct 8 ms 1152 KB Output is correct
43 Correct 11 ms 1152 KB Output is correct
44 Correct 9 ms 1152 KB Output is correct
45 Correct 9 ms 1152 KB Output is correct
46 Correct 11 ms 1152 KB Output is correct
47 Correct 11 ms 1152 KB Output is correct
48 Correct 8 ms 1152 KB Output is correct
49 Correct 6 ms 1152 KB Output is correct
50 Correct 6 ms 1152 KB Output is correct
51 Correct 7 ms 1152 KB Output is correct
52 Correct 8 ms 1152 KB Output is correct
53 Correct 9 ms 1152 KB Output is correct
54 Correct 6 ms 896 KB Output is correct
55 Correct 5 ms 768 KB Output is correct
56 Correct 5 ms 768 KB Output is correct
57 Correct 5 ms 768 KB Output is correct
58 Correct 6 ms 768 KB Output is correct
59 Correct 546 ms 4348 KB Output is correct
60 Correct 490 ms 4344 KB Output is correct
61 Correct 453 ms 4376 KB Output is correct
62 Correct 598 ms 4444 KB Output is correct
63 Correct 566 ms 4224 KB Output is correct
64 Correct 722 ms 4276 KB Output is correct
65 Correct 721 ms 4316 KB Output is correct
66 Correct 650 ms 4428 KB Output is correct
67 Correct 724 ms 4572 KB Output is correct
68 Correct 752 ms 4444 KB Output is correct
69 Correct 504 ms 4344 KB Output is correct
70 Correct 561 ms 4344 KB Output is correct
71 Correct 474 ms 4344 KB Output is correct
72 Correct 513 ms 4344 KB Output is correct
73 Correct 550 ms 4436 KB Output is correct
74 Correct 77 ms 1024 KB Output is correct
75 Correct 72 ms 1024 KB Output is correct
76 Correct 73 ms 1024 KB Output is correct
77 Correct 74 ms 1024 KB Output is correct
78 Correct 77 ms 1144 KB Output is correct