# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
139849 |
2019-08-01T14:34:59 Z |
Saboon |
Boat (APIO16_boat) |
C++14 |
|
1012 ms |
6520 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 |
511 ms |
6392 KB |
Output is correct |
2 |
Correct |
499 ms |
6264 KB |
Output is correct |
3 |
Correct |
539 ms |
6392 KB |
Output is correct |
4 |
Correct |
516 ms |
6320 KB |
Output is correct |
5 |
Correct |
527 ms |
6316 KB |
Output is correct |
6 |
Correct |
508 ms |
6316 KB |
Output is correct |
7 |
Correct |
499 ms |
6392 KB |
Output is correct |
8 |
Correct |
506 ms |
6392 KB |
Output is correct |
9 |
Correct |
500 ms |
6392 KB |
Output is correct |
10 |
Correct |
508 ms |
6392 KB |
Output is correct |
11 |
Correct |
513 ms |
6316 KB |
Output is correct |
12 |
Correct |
503 ms |
6392 KB |
Output is correct |
13 |
Correct |
510 ms |
6392 KB |
Output is correct |
14 |
Correct |
500 ms |
6264 KB |
Output is correct |
15 |
Correct |
499 ms |
6392 KB |
Output is correct |
16 |
Correct |
303 ms |
6264 KB |
Output is correct |
17 |
Correct |
324 ms |
6264 KB |
Output is correct |
18 |
Correct |
296 ms |
6264 KB |
Output is correct |
19 |
Correct |
307 ms |
6264 KB |
Output is correct |
20 |
Correct |
296 ms |
6264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
511 ms |
6392 KB |
Output is correct |
2 |
Correct |
499 ms |
6264 KB |
Output is correct |
3 |
Correct |
539 ms |
6392 KB |
Output is correct |
4 |
Correct |
516 ms |
6320 KB |
Output is correct |
5 |
Correct |
527 ms |
6316 KB |
Output is correct |
6 |
Correct |
508 ms |
6316 KB |
Output is correct |
7 |
Correct |
499 ms |
6392 KB |
Output is correct |
8 |
Correct |
506 ms |
6392 KB |
Output is correct |
9 |
Correct |
500 ms |
6392 KB |
Output is correct |
10 |
Correct |
508 ms |
6392 KB |
Output is correct |
11 |
Correct |
513 ms |
6316 KB |
Output is correct |
12 |
Correct |
503 ms |
6392 KB |
Output is correct |
13 |
Correct |
510 ms |
6392 KB |
Output is correct |
14 |
Correct |
500 ms |
6264 KB |
Output is correct |
15 |
Correct |
499 ms |
6392 KB |
Output is correct |
16 |
Correct |
303 ms |
6264 KB |
Output is correct |
17 |
Correct |
324 ms |
6264 KB |
Output is correct |
18 |
Correct |
296 ms |
6264 KB |
Output is correct |
19 |
Correct |
307 ms |
6264 KB |
Output is correct |
20 |
Correct |
296 ms |
6264 KB |
Output is correct |
21 |
Correct |
795 ms |
6328 KB |
Output is correct |
22 |
Correct |
782 ms |
6520 KB |
Output is correct |
23 |
Correct |
814 ms |
6392 KB |
Output is correct |
24 |
Correct |
802 ms |
6396 KB |
Output is correct |
25 |
Correct |
783 ms |
6392 KB |
Output is correct |
26 |
Correct |
963 ms |
6264 KB |
Output is correct |
27 |
Correct |
1004 ms |
6392 KB |
Output is correct |
28 |
Correct |
907 ms |
6364 KB |
Output is correct |
29 |
Correct |
894 ms |
6364 KB |
Output is correct |
30 |
Correct |
510 ms |
6264 KB |
Output is correct |
31 |
Correct |
507 ms |
6468 KB |
Output is correct |
32 |
Correct |
539 ms |
6468 KB |
Output is correct |
33 |
Correct |
529 ms |
6264 KB |
Output is correct |
34 |
Correct |
507 ms |
6316 KB |
Output is correct |
35 |
Correct |
506 ms |
6392 KB |
Output is correct |
36 |
Correct |
505 ms |
6264 KB |
Output is correct |
37 |
Correct |
516 ms |
6364 KB |
Output is correct |
38 |
Correct |
510 ms |
6396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
6392 KB |
Output is correct |
2 |
Correct |
61 ms |
6440 KB |
Output is correct |
3 |
Correct |
64 ms |
6392 KB |
Output is correct |
4 |
Correct |
63 ms |
6264 KB |
Output is correct |
5 |
Correct |
63 ms |
6268 KB |
Output is correct |
6 |
Correct |
63 ms |
6264 KB |
Output is correct |
7 |
Correct |
65 ms |
6308 KB |
Output is correct |
8 |
Correct |
63 ms |
6264 KB |
Output is correct |
9 |
Correct |
63 ms |
6264 KB |
Output is correct |
10 |
Correct |
66 ms |
6392 KB |
Output is correct |
11 |
Correct |
60 ms |
6264 KB |
Output is correct |
12 |
Correct |
61 ms |
6264 KB |
Output is correct |
13 |
Correct |
61 ms |
6264 KB |
Output is correct |
14 |
Correct |
63 ms |
6264 KB |
Output is correct |
15 |
Correct |
61 ms |
6264 KB |
Output is correct |
16 |
Correct |
60 ms |
6312 KB |
Output is correct |
17 |
Correct |
61 ms |
6312 KB |
Output is correct |
18 |
Correct |
59 ms |
6264 KB |
Output is correct |
19 |
Correct |
59 ms |
6308 KB |
Output is correct |
20 |
Correct |
61 ms |
6312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
511 ms |
6392 KB |
Output is correct |
2 |
Correct |
499 ms |
6264 KB |
Output is correct |
3 |
Correct |
539 ms |
6392 KB |
Output is correct |
4 |
Correct |
516 ms |
6320 KB |
Output is correct |
5 |
Correct |
527 ms |
6316 KB |
Output is correct |
6 |
Correct |
508 ms |
6316 KB |
Output is correct |
7 |
Correct |
499 ms |
6392 KB |
Output is correct |
8 |
Correct |
506 ms |
6392 KB |
Output is correct |
9 |
Correct |
500 ms |
6392 KB |
Output is correct |
10 |
Correct |
508 ms |
6392 KB |
Output is correct |
11 |
Correct |
513 ms |
6316 KB |
Output is correct |
12 |
Correct |
503 ms |
6392 KB |
Output is correct |
13 |
Correct |
510 ms |
6392 KB |
Output is correct |
14 |
Correct |
500 ms |
6264 KB |
Output is correct |
15 |
Correct |
499 ms |
6392 KB |
Output is correct |
16 |
Correct |
303 ms |
6264 KB |
Output is correct |
17 |
Correct |
324 ms |
6264 KB |
Output is correct |
18 |
Correct |
296 ms |
6264 KB |
Output is correct |
19 |
Correct |
307 ms |
6264 KB |
Output is correct |
20 |
Correct |
296 ms |
6264 KB |
Output is correct |
21 |
Correct |
795 ms |
6328 KB |
Output is correct |
22 |
Correct |
782 ms |
6520 KB |
Output is correct |
23 |
Correct |
814 ms |
6392 KB |
Output is correct |
24 |
Correct |
802 ms |
6396 KB |
Output is correct |
25 |
Correct |
783 ms |
6392 KB |
Output is correct |
26 |
Correct |
963 ms |
6264 KB |
Output is correct |
27 |
Correct |
1004 ms |
6392 KB |
Output is correct |
28 |
Correct |
907 ms |
6364 KB |
Output is correct |
29 |
Correct |
894 ms |
6364 KB |
Output is correct |
30 |
Correct |
510 ms |
6264 KB |
Output is correct |
31 |
Correct |
507 ms |
6468 KB |
Output is correct |
32 |
Correct |
539 ms |
6468 KB |
Output is correct |
33 |
Correct |
529 ms |
6264 KB |
Output is correct |
34 |
Correct |
507 ms |
6316 KB |
Output is correct |
35 |
Correct |
506 ms |
6392 KB |
Output is correct |
36 |
Correct |
505 ms |
6264 KB |
Output is correct |
37 |
Correct |
516 ms |
6364 KB |
Output is correct |
38 |
Correct |
510 ms |
6396 KB |
Output is correct |
39 |
Correct |
63 ms |
6392 KB |
Output is correct |
40 |
Correct |
61 ms |
6440 KB |
Output is correct |
41 |
Correct |
64 ms |
6392 KB |
Output is correct |
42 |
Correct |
63 ms |
6264 KB |
Output is correct |
43 |
Correct |
63 ms |
6268 KB |
Output is correct |
44 |
Correct |
63 ms |
6264 KB |
Output is correct |
45 |
Correct |
65 ms |
6308 KB |
Output is correct |
46 |
Correct |
63 ms |
6264 KB |
Output is correct |
47 |
Correct |
63 ms |
6264 KB |
Output is correct |
48 |
Correct |
66 ms |
6392 KB |
Output is correct |
49 |
Correct |
60 ms |
6264 KB |
Output is correct |
50 |
Correct |
61 ms |
6264 KB |
Output is correct |
51 |
Correct |
61 ms |
6264 KB |
Output is correct |
52 |
Correct |
63 ms |
6264 KB |
Output is correct |
53 |
Correct |
61 ms |
6264 KB |
Output is correct |
54 |
Correct |
60 ms |
6312 KB |
Output is correct |
55 |
Correct |
61 ms |
6312 KB |
Output is correct |
56 |
Correct |
59 ms |
6264 KB |
Output is correct |
57 |
Correct |
59 ms |
6308 KB |
Output is correct |
58 |
Correct |
61 ms |
6312 KB |
Output is correct |
59 |
Correct |
866 ms |
6324 KB |
Output is correct |
60 |
Correct |
827 ms |
6392 KB |
Output is correct |
61 |
Correct |
805 ms |
6320 KB |
Output is correct |
62 |
Correct |
842 ms |
6264 KB |
Output is correct |
63 |
Correct |
831 ms |
6264 KB |
Output is correct |
64 |
Correct |
999 ms |
6392 KB |
Output is correct |
65 |
Correct |
994 ms |
6324 KB |
Output is correct |
66 |
Correct |
994 ms |
6264 KB |
Output is correct |
67 |
Correct |
1012 ms |
6328 KB |
Output is correct |
68 |
Correct |
994 ms |
6392 KB |
Output is correct |
69 |
Correct |
761 ms |
6264 KB |
Output is correct |
70 |
Correct |
761 ms |
6264 KB |
Output is correct |
71 |
Correct |
746 ms |
6264 KB |
Output is correct |
72 |
Correct |
768 ms |
6332 KB |
Output is correct |
73 |
Correct |
771 ms |
6352 KB |
Output is correct |
74 |
Correct |
362 ms |
6392 KB |
Output is correct |
75 |
Correct |
370 ms |
6392 KB |
Output is correct |
76 |
Correct |
369 ms |
6280 KB |
Output is correct |
77 |
Correct |
360 ms |
6264 KB |
Output is correct |
78 |
Correct |
365 ms |
6364 KB |
Output is correct |