Submission #252196

# Submission time Handle Problem Language Result Execution time Memory
252196 2020-07-24T16:04:45 Z Berted Boat (APIO16_boat) C++14
100 / 100
1273 ms 24056 KB
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

const ll MD = 1e9 + 7;

ll dp[501][2002], pf[501][2002], pre[2002][501];
int n, a[501], b[501], c[2002], sz = 1;

inline ll pw(ll b, ll e)
{
	e = (e + MD - 1) % (MD - 1);
	ll t = 1;
	while (e)
	{
		if (e & 1) {t = (t * b) % MD;}
		b = (b * b) % MD; e >>= 1;
	}
	return t;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
		c[sz++] = a[i];
		c[sz++] = a[i] - 1;
		c[sz++] = b[i] + 1;
		c[sz++] = b[i];
	}
	sort(c, c + sz);
	sz = unique(c, c + sz) - c;

	for (int i = 1; i < sz; i++)
	{
		ll cur = 1;
		for (int j = 0; j <= n; j++)
		{
			pre[i][j] = cur;
			cur = (cur * (c[i] - c[i - 1] + j)) % MD;
			cur = (cur * pw(j + 1, -1)) % MD;
		}
	}

	dp[0][0] = 1;
	pf[0][0] = 1;
	for (int j = 1; j < sz; j++) {pf[0][j] = pf[0][j - 1];}
	for (int i = 1; i <= n; i++)
	{
		pf[i][0] = dp[i][0] = 1;
		for (int j = 1; j < sz; j++)
		{
			int kk = 0;
			for (int k = i - 1; k >= 0; k--)
			{
				kk += (a[k] <= c[j - 1] + 1) && (c[j] <= b[k]);
				if (kk && ((a[k] <= c[j - 1] + 1) && (c[j] <= b[k])))
				{
					dp[i][j] = (dp[i][j] + pf[k][j - 1] * pre[j][kk] % MD) % MD;
				}
			}
			// cout << "DP " << i << " " << j << " " << dp[i][j] << "\n";
			pf[i][j] = (pf[i][j - 1] + dp[i][j]) % MD;
		}
	}
	ll res = 0;
	for (int j = 1; j < sz; j++) res = (res + dp[n][j]) % MD;
	cout << res << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 564 ms 21880 KB Output is correct
2 Correct 565 ms 21868 KB Output is correct
3 Correct 557 ms 22008 KB Output is correct
4 Correct 560 ms 21840 KB Output is correct
5 Correct 559 ms 21988 KB Output is correct
6 Correct 425 ms 20336 KB Output is correct
7 Correct 395 ms 20088 KB Output is correct
8 Correct 419 ms 20856 KB Output is correct
9 Correct 416 ms 20856 KB Output is correct
10 Correct 410 ms 20984 KB Output is correct
11 Correct 417 ms 20856 KB Output is correct
12 Correct 424 ms 21624 KB Output is correct
13 Correct 415 ms 20984 KB Output is correct
14 Correct 380 ms 20216 KB Output is correct
15 Correct 417 ms 21244 KB Output is correct
16 Correct 114 ms 7416 KB Output is correct
17 Correct 116 ms 7672 KB Output is correct
18 Correct 118 ms 7544 KB Output is correct
19 Correct 119 ms 7672 KB Output is correct
20 Correct 117 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 564 ms 21880 KB Output is correct
2 Correct 565 ms 21868 KB Output is correct
3 Correct 557 ms 22008 KB Output is correct
4 Correct 560 ms 21840 KB Output is correct
5 Correct 559 ms 21988 KB Output is correct
6 Correct 425 ms 20336 KB Output is correct
7 Correct 395 ms 20088 KB Output is correct
8 Correct 419 ms 20856 KB Output is correct
9 Correct 416 ms 20856 KB Output is correct
10 Correct 410 ms 20984 KB Output is correct
11 Correct 417 ms 20856 KB Output is correct
12 Correct 424 ms 21624 KB Output is correct
13 Correct 415 ms 20984 KB Output is correct
14 Correct 380 ms 20216 KB Output is correct
15 Correct 417 ms 21244 KB Output is correct
16 Correct 114 ms 7416 KB Output is correct
17 Correct 116 ms 7672 KB Output is correct
18 Correct 118 ms 7544 KB Output is correct
19 Correct 119 ms 7672 KB Output is correct
20 Correct 117 ms 7544 KB Output is correct
21 Correct 816 ms 22708 KB Output is correct
22 Correct 830 ms 22600 KB Output is correct
23 Correct 817 ms 22648 KB Output is correct
24 Correct 794 ms 22520 KB Output is correct
25 Correct 800 ms 22776 KB Output is correct
26 Correct 843 ms 22136 KB Output is correct
27 Correct 880 ms 22264 KB Output is correct
28 Correct 882 ms 22392 KB Output is correct
29 Correct 867 ms 22136 KB Output is correct
30 Correct 545 ms 23416 KB Output is correct
31 Correct 524 ms 22520 KB Output is correct
32 Correct 552 ms 23032 KB Output is correct
33 Correct 523 ms 23288 KB Output is correct
34 Correct 515 ms 22776 KB Output is correct
35 Correct 578 ms 21880 KB Output is correct
36 Correct 573 ms 21880 KB Output is correct
37 Correct 569 ms 22008 KB Output is correct
38 Correct 571 ms 21880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 3328 KB Output is correct
2 Correct 14 ms 3328 KB Output is correct
3 Correct 14 ms 3328 KB Output is correct
4 Correct 14 ms 3328 KB Output is correct
5 Correct 14 ms 3328 KB Output is correct
6 Correct 16 ms 3328 KB Output is correct
7 Correct 16 ms 3328 KB Output is correct
8 Correct 15 ms 3328 KB Output is correct
9 Correct 16 ms 3312 KB Output is correct
10 Correct 15 ms 3328 KB Output is correct
11 Correct 16 ms 3328 KB Output is correct
12 Correct 14 ms 3328 KB Output is correct
13 Correct 15 ms 3328 KB Output is correct
14 Correct 14 ms 3328 KB Output is correct
15 Correct 14 ms 3328 KB Output is correct
16 Correct 8 ms 2304 KB Output is correct
17 Correct 8 ms 2200 KB Output is correct
18 Correct 8 ms 2304 KB Output is correct
19 Correct 8 ms 2304 KB Output is correct
20 Correct 11 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 564 ms 21880 KB Output is correct
2 Correct 565 ms 21868 KB Output is correct
3 Correct 557 ms 22008 KB Output is correct
4 Correct 560 ms 21840 KB Output is correct
5 Correct 559 ms 21988 KB Output is correct
6 Correct 425 ms 20336 KB Output is correct
7 Correct 395 ms 20088 KB Output is correct
8 Correct 419 ms 20856 KB Output is correct
9 Correct 416 ms 20856 KB Output is correct
10 Correct 410 ms 20984 KB Output is correct
11 Correct 417 ms 20856 KB Output is correct
12 Correct 424 ms 21624 KB Output is correct
13 Correct 415 ms 20984 KB Output is correct
14 Correct 380 ms 20216 KB Output is correct
15 Correct 417 ms 21244 KB Output is correct
16 Correct 114 ms 7416 KB Output is correct
17 Correct 116 ms 7672 KB Output is correct
18 Correct 118 ms 7544 KB Output is correct
19 Correct 119 ms 7672 KB Output is correct
20 Correct 117 ms 7544 KB Output is correct
21 Correct 816 ms 22708 KB Output is correct
22 Correct 830 ms 22600 KB Output is correct
23 Correct 817 ms 22648 KB Output is correct
24 Correct 794 ms 22520 KB Output is correct
25 Correct 800 ms 22776 KB Output is correct
26 Correct 843 ms 22136 KB Output is correct
27 Correct 880 ms 22264 KB Output is correct
28 Correct 882 ms 22392 KB Output is correct
29 Correct 867 ms 22136 KB Output is correct
30 Correct 545 ms 23416 KB Output is correct
31 Correct 524 ms 22520 KB Output is correct
32 Correct 552 ms 23032 KB Output is correct
33 Correct 523 ms 23288 KB Output is correct
34 Correct 515 ms 22776 KB Output is correct
35 Correct 578 ms 21880 KB Output is correct
36 Correct 573 ms 21880 KB Output is correct
37 Correct 569 ms 22008 KB Output is correct
38 Correct 571 ms 21880 KB Output is correct
39 Correct 14 ms 3328 KB Output is correct
40 Correct 14 ms 3328 KB Output is correct
41 Correct 14 ms 3328 KB Output is correct
42 Correct 14 ms 3328 KB Output is correct
43 Correct 14 ms 3328 KB Output is correct
44 Correct 16 ms 3328 KB Output is correct
45 Correct 16 ms 3328 KB Output is correct
46 Correct 15 ms 3328 KB Output is correct
47 Correct 16 ms 3312 KB Output is correct
48 Correct 15 ms 3328 KB Output is correct
49 Correct 16 ms 3328 KB Output is correct
50 Correct 14 ms 3328 KB Output is correct
51 Correct 15 ms 3328 KB Output is correct
52 Correct 14 ms 3328 KB Output is correct
53 Correct 14 ms 3328 KB Output is correct
54 Correct 8 ms 2304 KB Output is correct
55 Correct 8 ms 2200 KB Output is correct
56 Correct 8 ms 2304 KB Output is correct
57 Correct 8 ms 2304 KB Output is correct
58 Correct 11 ms 2300 KB Output is correct
59 Correct 1014 ms 24004 KB Output is correct
60 Correct 949 ms 23848 KB Output is correct
61 Correct 1014 ms 24008 KB Output is correct
62 Correct 1038 ms 24056 KB Output is correct
63 Correct 970 ms 24036 KB Output is correct
64 Correct 1135 ms 23940 KB Output is correct
65 Correct 1118 ms 23696 KB Output is correct
66 Correct 1119 ms 23928 KB Output is correct
67 Correct 1088 ms 23712 KB Output is correct
68 Correct 1273 ms 23928 KB Output is correct
69 Correct 990 ms 24016 KB Output is correct
70 Correct 1018 ms 23928 KB Output is correct
71 Correct 1000 ms 23856 KB Output is correct
72 Correct 972 ms 24056 KB Output is correct
73 Correct 998 ms 24056 KB Output is correct
74 Correct 167 ms 7640 KB Output is correct
75 Correct 167 ms 7676 KB Output is correct
76 Correct 163 ms 7672 KB Output is correct
77 Correct 166 ms 7756 KB Output is correct
78 Correct 178 ms 7800 KB Output is correct