Submission #111378

# Submission time Handle Problem Language Result Execution time Memory
111378 2019-05-15T04:11:05 Z diamond_duke Boat (APIO16_boat) C++11
100 / 100
1049 ms 6400 KB
#include <algorithm>
#include <cstring>
#include <cstdio>
using ll = long long;
constexpr int MOD = 1e9 + 7;
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], nxt[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++)
	{
		memcpy(nxt, dp, sizeof(dp));
		memset(sum, 0, sizeof(sum));
		for (int j = 0; j < cnt; j++)
		{
			for (int k = 0; k <= i; k++)
				sum[j + 1][k] = (sum[j][k] + dp[j][k]) % MOD;
		}
		for (int j = lp[i]; j < rp[i]; j++)
		{
			int len = app[j + 1] - app[j];
			for (int k = 0; k <= i; k++)
			{
				nxt[j][k + 1] = (nxt[j][k + 1] + (ll)dp[j][k] * (len - k) % MOD * inv[k + 1]) % MOD;
				nxt[j][1] = (nxt[j][1] + (ll)sum[j][k] * len) % MOD;
			}
		}
		memcpy(dp, nxt, sizeof(dp));
	}
	int ans = 0;
	for (int i = 0; i < cnt; i++)
	{
		for (int j = 0; j <= n; j++)
			ans = (ans + dp[i][j]) % MOD;
	}
	printf("%d\n", (ans + MOD - 1) % MOD);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
boat.cpp:26: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 525 ms 6272 KB Output is correct
2 Correct 450 ms 6328 KB Output is correct
3 Correct 424 ms 6272 KB Output is correct
4 Correct 512 ms 6272 KB Output is correct
5 Correct 447 ms 6340 KB Output is correct
6 Correct 503 ms 6272 KB Output is correct
7 Correct 531 ms 6272 KB Output is correct
8 Correct 658 ms 6272 KB Output is correct
9 Correct 491 ms 6272 KB Output is correct
10 Correct 509 ms 6364 KB Output is correct
11 Correct 477 ms 6272 KB Output is correct
12 Correct 556 ms 6392 KB Output is correct
13 Correct 452 ms 6392 KB Output is correct
14 Correct 510 ms 6320 KB Output is correct
15 Correct 494 ms 6272 KB Output is correct
16 Correct 252 ms 6272 KB Output is correct
17 Correct 303 ms 6272 KB Output is correct
18 Correct 316 ms 6392 KB Output is correct
19 Correct 288 ms 6392 KB Output is correct
20 Correct 311 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 525 ms 6272 KB Output is correct
2 Correct 450 ms 6328 KB Output is correct
3 Correct 424 ms 6272 KB Output is correct
4 Correct 512 ms 6272 KB Output is correct
5 Correct 447 ms 6340 KB Output is correct
6 Correct 503 ms 6272 KB Output is correct
7 Correct 531 ms 6272 KB Output is correct
8 Correct 658 ms 6272 KB Output is correct
9 Correct 491 ms 6272 KB Output is correct
10 Correct 509 ms 6364 KB Output is correct
11 Correct 477 ms 6272 KB Output is correct
12 Correct 556 ms 6392 KB Output is correct
13 Correct 452 ms 6392 KB Output is correct
14 Correct 510 ms 6320 KB Output is correct
15 Correct 494 ms 6272 KB Output is correct
16 Correct 252 ms 6272 KB Output is correct
17 Correct 303 ms 6272 KB Output is correct
18 Correct 316 ms 6392 KB Output is correct
19 Correct 288 ms 6392 KB Output is correct
20 Correct 311 ms 6272 KB Output is correct
21 Correct 754 ms 6304 KB Output is correct
22 Correct 726 ms 6308 KB Output is correct
23 Correct 757 ms 6364 KB Output is correct
24 Correct 740 ms 6272 KB Output is correct
25 Correct 864 ms 6392 KB Output is correct
26 Correct 912 ms 6396 KB Output is correct
27 Correct 892 ms 6392 KB Output is correct
28 Correct 1010 ms 6392 KB Output is correct
29 Correct 804 ms 6392 KB Output is correct
30 Correct 498 ms 6272 KB Output is correct
31 Correct 660 ms 6368 KB Output is correct
32 Correct 552 ms 6272 KB Output is correct
33 Correct 494 ms 6392 KB Output is correct
34 Correct 486 ms 6392 KB Output is correct
35 Correct 508 ms 6272 KB Output is correct
36 Correct 507 ms 6308 KB Output is correct
37 Correct 472 ms 6272 KB Output is correct
38 Correct 538 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 6272 KB Output is correct
2 Correct 70 ms 6272 KB Output is correct
3 Correct 63 ms 6392 KB Output is correct
4 Correct 60 ms 6272 KB Output is correct
5 Correct 60 ms 6272 KB Output is correct
6 Correct 60 ms 6272 KB Output is correct
7 Correct 65 ms 6272 KB Output is correct
8 Correct 56 ms 6400 KB Output is correct
9 Correct 64 ms 6392 KB Output is correct
10 Correct 65 ms 6272 KB Output is correct
11 Correct 59 ms 6272 KB Output is correct
12 Correct 59 ms 6272 KB Output is correct
13 Correct 62 ms 6272 KB Output is correct
14 Correct 66 ms 6272 KB Output is correct
15 Correct 69 ms 6308 KB Output is correct
16 Correct 63 ms 6272 KB Output is correct
17 Correct 57 ms 6344 KB Output is correct
18 Correct 55 ms 6308 KB Output is correct
19 Correct 68 ms 6272 KB Output is correct
20 Correct 58 ms 6392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 525 ms 6272 KB Output is correct
2 Correct 450 ms 6328 KB Output is correct
3 Correct 424 ms 6272 KB Output is correct
4 Correct 512 ms 6272 KB Output is correct
5 Correct 447 ms 6340 KB Output is correct
6 Correct 503 ms 6272 KB Output is correct
7 Correct 531 ms 6272 KB Output is correct
8 Correct 658 ms 6272 KB Output is correct
9 Correct 491 ms 6272 KB Output is correct
10 Correct 509 ms 6364 KB Output is correct
11 Correct 477 ms 6272 KB Output is correct
12 Correct 556 ms 6392 KB Output is correct
13 Correct 452 ms 6392 KB Output is correct
14 Correct 510 ms 6320 KB Output is correct
15 Correct 494 ms 6272 KB Output is correct
16 Correct 252 ms 6272 KB Output is correct
17 Correct 303 ms 6272 KB Output is correct
18 Correct 316 ms 6392 KB Output is correct
19 Correct 288 ms 6392 KB Output is correct
20 Correct 311 ms 6272 KB Output is correct
21 Correct 754 ms 6304 KB Output is correct
22 Correct 726 ms 6308 KB Output is correct
23 Correct 757 ms 6364 KB Output is correct
24 Correct 740 ms 6272 KB Output is correct
25 Correct 864 ms 6392 KB Output is correct
26 Correct 912 ms 6396 KB Output is correct
27 Correct 892 ms 6392 KB Output is correct
28 Correct 1010 ms 6392 KB Output is correct
29 Correct 804 ms 6392 KB Output is correct
30 Correct 498 ms 6272 KB Output is correct
31 Correct 660 ms 6368 KB Output is correct
32 Correct 552 ms 6272 KB Output is correct
33 Correct 494 ms 6392 KB Output is correct
34 Correct 486 ms 6392 KB Output is correct
35 Correct 508 ms 6272 KB Output is correct
36 Correct 507 ms 6308 KB Output is correct
37 Correct 472 ms 6272 KB Output is correct
38 Correct 538 ms 6272 KB Output is correct
39 Correct 56 ms 6272 KB Output is correct
40 Correct 70 ms 6272 KB Output is correct
41 Correct 63 ms 6392 KB Output is correct
42 Correct 60 ms 6272 KB Output is correct
43 Correct 60 ms 6272 KB Output is correct
44 Correct 60 ms 6272 KB Output is correct
45 Correct 65 ms 6272 KB Output is correct
46 Correct 56 ms 6400 KB Output is correct
47 Correct 64 ms 6392 KB Output is correct
48 Correct 65 ms 6272 KB Output is correct
49 Correct 59 ms 6272 KB Output is correct
50 Correct 59 ms 6272 KB Output is correct
51 Correct 62 ms 6272 KB Output is correct
52 Correct 66 ms 6272 KB Output is correct
53 Correct 69 ms 6308 KB Output is correct
54 Correct 63 ms 6272 KB Output is correct
55 Correct 57 ms 6344 KB Output is correct
56 Correct 55 ms 6308 KB Output is correct
57 Correct 68 ms 6272 KB Output is correct
58 Correct 58 ms 6392 KB Output is correct
59 Correct 848 ms 6316 KB Output is correct
60 Correct 704 ms 6272 KB Output is correct
61 Correct 830 ms 6272 KB Output is correct
62 Correct 933 ms 6396 KB Output is correct
63 Correct 800 ms 6340 KB Output is correct
64 Correct 998 ms 6272 KB Output is correct
65 Correct 1035 ms 6364 KB Output is correct
66 Correct 1049 ms 6304 KB Output is correct
67 Correct 964 ms 6392 KB Output is correct
68 Correct 939 ms 6312 KB Output is correct
69 Correct 777 ms 6272 KB Output is correct
70 Correct 786 ms 6392 KB Output is correct
71 Correct 782 ms 6272 KB Output is correct
72 Correct 844 ms 6392 KB Output is correct
73 Correct 718 ms 6392 KB Output is correct
74 Correct 382 ms 6364 KB Output is correct
75 Correct 400 ms 6272 KB Output is correct
76 Correct 369 ms 6400 KB Output is correct
77 Correct 353 ms 6392 KB Output is correct
78 Correct 373 ms 6392 KB Output is correct