Submission #455011

# Submission time Handle Problem Language Result Execution time Memory
455011 2021-08-05T11:33:36 Z nonsensenonsense1 Boat (APIO16_boat) C++17
100 / 100
698 ms 4372 KB
#include <cstdio>
#include <algorithm>

const int md = 1000000007;

inline int add(int a, int b) 
{
	a += b;
	if (a >= md) a -= md;
	return a;
}
inline int sub(int a, int b) 
{
	a -= b;
	if (a < 0) a += md;
	return a;
}
inline int mul(int a, int b) 
{
	return (long long)a * b % md;
}
int po(int a, int b) 
{
	int r = 1;
	while (b) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}
inline int inv(int a) 
{
	return po(a, md - 2);
}
inline int di(int a, int b) 
{
	return mul(a, inv(b));
}

const int N = 505;
int n, d[N << 1], l[N], r[N], a[N << 1], p[N << 1][N], amt[N << 1], ncr[N << 1][N];

int main() 
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", l + i, r + i);
		a[i << 1] = l[i];
		a[i << 1 | 1] = r[i] + 1;
	}
	std::sort(a, a + n * 2);
	int len = std::unique(a, a + n * 2) - a;
	d[0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = len - 1; j >= 1; --j) if (l[i] <= a[j - 1] && r[i] >= a[j] - 1) {
			if (!amt[j]) ncr[j][0] = a[j] - a[j - 1];
			else ncr[j][amt[j]] = di(mul(ncr[j][amt[j] - 1], ncr[j][0] - amt[j]), amt[j] + 1);
			for (int k = amt[j]; k > 0; --k) {
				p[j][k] = add(p[j][k], p[j][k - 1]);
				d[j] = add(d[j], mul(p[j][k - 1], ncr[j][k]));
			}
			for (int k = 0; k < j; ++k) {
				p[j][0] = add(p[j][0], d[k]);
				d[j] = add(d[j], mul(ncr[j][0], d[k]));
			}
			++amt[j];
		}
	}
	int ans = 0;
	for (int i = 1; i < len; ++i) ans = add(ans, d[i]);
	printf("%d\n", ans);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
boat.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d%d", l + i, r + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4172 KB Output is correct
2 Correct 4 ms 4172 KB Output is correct
3 Correct 4 ms 4160 KB Output is correct
4 Correct 4 ms 4172 KB Output is correct
5 Correct 4 ms 4172 KB Output is correct
6 Correct 4 ms 4172 KB Output is correct
7 Correct 4 ms 4176 KB Output is correct
8 Correct 4 ms 4172 KB Output is correct
9 Correct 5 ms 4172 KB Output is correct
10 Correct 4 ms 4172 KB Output is correct
11 Correct 4 ms 4172 KB Output is correct
12 Correct 4 ms 4172 KB Output is correct
13 Correct 4 ms 4172 KB Output is correct
14 Correct 4 ms 4172 KB Output is correct
15 Correct 4 ms 4172 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4172 KB Output is correct
2 Correct 4 ms 4172 KB Output is correct
3 Correct 4 ms 4160 KB Output is correct
4 Correct 4 ms 4172 KB Output is correct
5 Correct 4 ms 4172 KB Output is correct
6 Correct 4 ms 4172 KB Output is correct
7 Correct 4 ms 4176 KB Output is correct
8 Correct 4 ms 4172 KB Output is correct
9 Correct 5 ms 4172 KB Output is correct
10 Correct 4 ms 4172 KB Output is correct
11 Correct 4 ms 4172 KB Output is correct
12 Correct 4 ms 4172 KB Output is correct
13 Correct 4 ms 4172 KB Output is correct
14 Correct 4 ms 4172 KB Output is correct
15 Correct 4 ms 4172 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 355 ms 3876 KB Output is correct
22 Correct 344 ms 4052 KB Output is correct
23 Correct 316 ms 3864 KB Output is correct
24 Correct 338 ms 3836 KB Output is correct
25 Correct 350 ms 3860 KB Output is correct
26 Correct 524 ms 3804 KB Output is correct
27 Correct 551 ms 3804 KB Output is correct
28 Correct 537 ms 3648 KB Output is correct
29 Correct 526 ms 3740 KB Output is correct
30 Correct 6 ms 4172 KB Output is correct
31 Correct 6 ms 4172 KB Output is correct
32 Correct 6 ms 4136 KB Output is correct
33 Correct 6 ms 4172 KB Output is correct
34 Correct 6 ms 4172 KB Output is correct
35 Correct 6 ms 4132 KB Output is correct
36 Correct 6 ms 4172 KB Output is correct
37 Correct 6 ms 4172 KB Output is correct
38 Correct 7 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 972 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 5 ms 972 KB Output is correct
4 Correct 5 ms 1100 KB Output is correct
5 Correct 5 ms 1100 KB Output is correct
6 Correct 8 ms 1056 KB Output is correct
7 Correct 8 ms 1100 KB Output is correct
8 Correct 8 ms 1100 KB Output is correct
9 Correct 8 ms 1056 KB Output is correct
10 Correct 8 ms 1100 KB Output is correct
11 Correct 5 ms 1100 KB Output is correct
12 Correct 6 ms 1096 KB Output is correct
13 Correct 5 ms 972 KB Output is correct
14 Correct 5 ms 1100 KB Output is correct
15 Correct 5 ms 972 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 3 ms 668 KB Output is correct
18 Correct 2 ms 716 KB Output is correct
19 Correct 3 ms 756 KB Output is correct
20 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4172 KB Output is correct
2 Correct 4 ms 4172 KB Output is correct
3 Correct 4 ms 4160 KB Output is correct
4 Correct 4 ms 4172 KB Output is correct
5 Correct 4 ms 4172 KB Output is correct
6 Correct 4 ms 4172 KB Output is correct
7 Correct 4 ms 4176 KB Output is correct
8 Correct 4 ms 4172 KB Output is correct
9 Correct 5 ms 4172 KB Output is correct
10 Correct 4 ms 4172 KB Output is correct
11 Correct 4 ms 4172 KB Output is correct
12 Correct 4 ms 4172 KB Output is correct
13 Correct 4 ms 4172 KB Output is correct
14 Correct 4 ms 4172 KB Output is correct
15 Correct 4 ms 4172 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 355 ms 3876 KB Output is correct
22 Correct 344 ms 4052 KB Output is correct
23 Correct 316 ms 3864 KB Output is correct
24 Correct 338 ms 3836 KB Output is correct
25 Correct 350 ms 3860 KB Output is correct
26 Correct 524 ms 3804 KB Output is correct
27 Correct 551 ms 3804 KB Output is correct
28 Correct 537 ms 3648 KB Output is correct
29 Correct 526 ms 3740 KB Output is correct
30 Correct 6 ms 4172 KB Output is correct
31 Correct 6 ms 4172 KB Output is correct
32 Correct 6 ms 4136 KB Output is correct
33 Correct 6 ms 4172 KB Output is correct
34 Correct 6 ms 4172 KB Output is correct
35 Correct 6 ms 4132 KB Output is correct
36 Correct 6 ms 4172 KB Output is correct
37 Correct 6 ms 4172 KB Output is correct
38 Correct 7 ms 4172 KB Output is correct
39 Correct 5 ms 972 KB Output is correct
40 Correct 4 ms 972 KB Output is correct
41 Correct 5 ms 972 KB Output is correct
42 Correct 5 ms 1100 KB Output is correct
43 Correct 5 ms 1100 KB Output is correct
44 Correct 8 ms 1056 KB Output is correct
45 Correct 8 ms 1100 KB Output is correct
46 Correct 8 ms 1100 KB Output is correct
47 Correct 8 ms 1056 KB Output is correct
48 Correct 8 ms 1100 KB Output is correct
49 Correct 5 ms 1100 KB Output is correct
50 Correct 6 ms 1096 KB Output is correct
51 Correct 5 ms 972 KB Output is correct
52 Correct 5 ms 1100 KB Output is correct
53 Correct 5 ms 972 KB Output is correct
54 Correct 3 ms 716 KB Output is correct
55 Correct 3 ms 668 KB Output is correct
56 Correct 2 ms 716 KB Output is correct
57 Correct 3 ms 756 KB Output is correct
58 Correct 3 ms 716 KB Output is correct
59 Correct 413 ms 4216 KB Output is correct
60 Correct 387 ms 4232 KB Output is correct
61 Correct 383 ms 4232 KB Output is correct
62 Correct 422 ms 4232 KB Output is correct
63 Correct 402 ms 4232 KB Output is correct
64 Correct 661 ms 4164 KB Output is correct
65 Correct 659 ms 4372 KB Output is correct
66 Correct 698 ms 4244 KB Output is correct
67 Correct 689 ms 4140 KB Output is correct
68 Correct 684 ms 4160 KB Output is correct
69 Correct 372 ms 4236 KB Output is correct
70 Correct 376 ms 4236 KB Output is correct
71 Correct 409 ms 4232 KB Output is correct
72 Correct 426 ms 4160 KB Output is correct
73 Correct 401 ms 4232 KB Output is correct
74 Correct 32 ms 932 KB Output is correct
75 Correct 31 ms 972 KB Output is correct
76 Correct 32 ms 972 KB Output is correct
77 Correct 43 ms 1032 KB Output is correct
78 Correct 32 ms 1000 KB Output is correct