답안 #111380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111380 2019-05-15T04:14:47 Z diamond_duke Boat (APIO16_boat) C++11
100 / 100
702 ms 4472 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], 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] + dp[j][k]) % MOD;
		}
		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;
				one = (one + (ll)sum[j][k] * len) % MOD;
			}
			dp[j][1] = (dp[j][1] + one) % MOD;
		}
	}
	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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 282 ms 4300 KB Output is correct
2 Correct 238 ms 4216 KB Output is correct
3 Correct 247 ms 4220 KB Output is correct
4 Correct 275 ms 4216 KB Output is correct
5 Correct 239 ms 4216 KB Output is correct
6 Correct 237 ms 4248 KB Output is correct
7 Correct 210 ms 4472 KB Output is correct
8 Correct 210 ms 4344 KB Output is correct
9 Correct 264 ms 4452 KB Output is correct
10 Correct 219 ms 4400 KB Output is correct
11 Correct 240 ms 4344 KB Output is correct
12 Correct 246 ms 4344 KB Output is correct
13 Correct 241 ms 4212 KB Output is correct
14 Correct 295 ms 4316 KB Output is correct
15 Correct 253 ms 4344 KB Output is correct
16 Correct 44 ms 1144 KB Output is correct
17 Correct 66 ms 1148 KB Output is correct
18 Correct 46 ms 1024 KB Output is correct
19 Correct 50 ms 1144 KB Output is correct
20 Correct 45 ms 1036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 282 ms 4300 KB Output is correct
2 Correct 238 ms 4216 KB Output is correct
3 Correct 247 ms 4220 KB Output is correct
4 Correct 275 ms 4216 KB Output is correct
5 Correct 239 ms 4216 KB Output is correct
6 Correct 237 ms 4248 KB Output is correct
7 Correct 210 ms 4472 KB Output is correct
8 Correct 210 ms 4344 KB Output is correct
9 Correct 264 ms 4452 KB Output is correct
10 Correct 219 ms 4400 KB Output is correct
11 Correct 240 ms 4344 KB Output is correct
12 Correct 246 ms 4344 KB Output is correct
13 Correct 241 ms 4212 KB Output is correct
14 Correct 295 ms 4316 KB Output is correct
15 Correct 253 ms 4344 KB Output is correct
16 Correct 44 ms 1144 KB Output is correct
17 Correct 66 ms 1148 KB Output is correct
18 Correct 46 ms 1024 KB Output is correct
19 Correct 50 ms 1144 KB Output is correct
20 Correct 45 ms 1036 KB Output is correct
21 Correct 520 ms 3996 KB Output is correct
22 Correct 497 ms 4216 KB Output is correct
23 Correct 490 ms 4076 KB Output is correct
24 Correct 453 ms 3840 KB Output is correct
25 Correct 460 ms 3960 KB Output is correct
26 Correct 662 ms 3788 KB Output is correct
27 Correct 581 ms 3832 KB Output is correct
28 Correct 522 ms 3804 KB Output is correct
29 Correct 531 ms 3832 KB Output is correct
30 Correct 242 ms 4240 KB Output is correct
31 Correct 288 ms 4296 KB Output is correct
32 Correct 253 ms 4296 KB Output is correct
33 Correct 269 ms 4400 KB Output is correct
34 Correct 231 ms 4292 KB Output is correct
35 Correct 240 ms 4344 KB Output is correct
36 Correct 256 ms 4404 KB Output is correct
37 Correct 214 ms 4216 KB Output is correct
38 Correct 266 ms 4412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1280 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 10 ms 1152 KB Output is correct
4 Correct 7 ms 1152 KB Output is correct
5 Correct 7 ms 1152 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 8 ms 1152 KB Output is correct
8 Correct 8 ms 1152 KB Output is correct
9 Correct 9 ms 1152 KB Output is correct
10 Correct 8 ms 1152 KB Output is correct
11 Correct 8 ms 1152 KB Output is correct
12 Correct 7 ms 1152 KB Output is correct
13 Correct 7 ms 1152 KB Output is correct
14 Correct 9 ms 1152 KB Output is correct
15 Correct 11 ms 1152 KB Output is correct
16 Correct 6 ms 768 KB Output is correct
17 Correct 7 ms 768 KB Output is correct
18 Correct 4 ms 768 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 282 ms 4300 KB Output is correct
2 Correct 238 ms 4216 KB Output is correct
3 Correct 247 ms 4220 KB Output is correct
4 Correct 275 ms 4216 KB Output is correct
5 Correct 239 ms 4216 KB Output is correct
6 Correct 237 ms 4248 KB Output is correct
7 Correct 210 ms 4472 KB Output is correct
8 Correct 210 ms 4344 KB Output is correct
9 Correct 264 ms 4452 KB Output is correct
10 Correct 219 ms 4400 KB Output is correct
11 Correct 240 ms 4344 KB Output is correct
12 Correct 246 ms 4344 KB Output is correct
13 Correct 241 ms 4212 KB Output is correct
14 Correct 295 ms 4316 KB Output is correct
15 Correct 253 ms 4344 KB Output is correct
16 Correct 44 ms 1144 KB Output is correct
17 Correct 66 ms 1148 KB Output is correct
18 Correct 46 ms 1024 KB Output is correct
19 Correct 50 ms 1144 KB Output is correct
20 Correct 45 ms 1036 KB Output is correct
21 Correct 520 ms 3996 KB Output is correct
22 Correct 497 ms 4216 KB Output is correct
23 Correct 490 ms 4076 KB Output is correct
24 Correct 453 ms 3840 KB Output is correct
25 Correct 460 ms 3960 KB Output is correct
26 Correct 662 ms 3788 KB Output is correct
27 Correct 581 ms 3832 KB Output is correct
28 Correct 522 ms 3804 KB Output is correct
29 Correct 531 ms 3832 KB Output is correct
30 Correct 242 ms 4240 KB Output is correct
31 Correct 288 ms 4296 KB Output is correct
32 Correct 253 ms 4296 KB Output is correct
33 Correct 269 ms 4400 KB Output is correct
34 Correct 231 ms 4292 KB Output is correct
35 Correct 240 ms 4344 KB Output is correct
36 Correct 256 ms 4404 KB Output is correct
37 Correct 214 ms 4216 KB Output is correct
38 Correct 266 ms 4412 KB Output is correct
39 Correct 7 ms 1280 KB Output is correct
40 Correct 6 ms 1152 KB Output is correct
41 Correct 10 ms 1152 KB Output is correct
42 Correct 7 ms 1152 KB Output is correct
43 Correct 7 ms 1152 KB Output is correct
44 Correct 11 ms 1152 KB Output is correct
45 Correct 8 ms 1152 KB Output is correct
46 Correct 8 ms 1152 KB Output is correct
47 Correct 9 ms 1152 KB Output is correct
48 Correct 8 ms 1152 KB Output is correct
49 Correct 8 ms 1152 KB Output is correct
50 Correct 7 ms 1152 KB Output is correct
51 Correct 7 ms 1152 KB Output is correct
52 Correct 9 ms 1152 KB Output is correct
53 Correct 11 ms 1152 KB Output is correct
54 Correct 6 ms 768 KB Output is correct
55 Correct 7 ms 768 KB Output is correct
56 Correct 4 ms 768 KB Output is correct
57 Correct 4 ms 768 KB Output is correct
58 Correct 6 ms 768 KB Output is correct
59 Correct 539 ms 4344 KB Output is correct
60 Correct 486 ms 4432 KB Output is correct
61 Correct 556 ms 4308 KB Output is correct
62 Correct 507 ms 4304 KB Output is correct
63 Correct 528 ms 4344 KB Output is correct
64 Correct 669 ms 4344 KB Output is correct
65 Correct 702 ms 4344 KB Output is correct
66 Correct 580 ms 4280 KB Output is correct
67 Correct 633 ms 4344 KB Output is correct
68 Correct 630 ms 4344 KB Output is correct
69 Correct 487 ms 4344 KB Output is correct
70 Correct 395 ms 4308 KB Output is correct
71 Correct 414 ms 4320 KB Output is correct
72 Correct 422 ms 4416 KB Output is correct
73 Correct 401 ms 4344 KB Output is correct
74 Correct 88 ms 1024 KB Output is correct
75 Correct 91 ms 1024 KB Output is correct
76 Correct 94 ms 1024 KB Output is correct
77 Correct 92 ms 1080 KB Output is correct
78 Correct 108 ms 1024 KB Output is correct