# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1031407 |
2024-07-22T19:57:10 Z |
Tob |
Boat (APIO16_boat) |
C++14 |
|
1002 ms |
7508 KB |
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const int N = 507, mod = 1e9 + 7;
int add(int x, int y) {return (x+y < mod) ? x+y : x+y-mod;}
int mul(int x, int y) {return (ll)x*y%mod;}
int n;
int aa[N], bb[N], a[N], b[N], dp[N][2*N], ch[N][2*N], c[N][2*N], inv[N], cho[N][N];
int Pow(int x, int y) {
int res = 1, pot = x;
while (y) {
if (y % 2) res = mul(res, pot);
pot = mul(pot, pot);
y /= 2;
}
return res;
}
int main () {
FIO;
inv[0] = 1;
for (int i = 1; i < N; i++) inv[i] = Pow(i, mod-2);
for (int i = 0; i < N; i++) {
cho[i][0] = 1;
for (int j = 1; j <= i; j++) cho[i][j] = add(cho[i-1][j], cho[i-1][j-1]);
}
cin >> n;
vector <int> v;
map <int, int> saz;
for (int i = 0; i < n; i++) {
cin >> aa[i] >> bb[i]; bb[i]++;
v.pb(aa[i]);
v.pb(bb[i]);
}
sort(all(v)); v.erase(unique(all(v)), v.end());
int siz = v.size()-1;
for (int i = 0; i <= siz; i++) saz[v[i]] = i;
for (int i = 0; i < n; i++) {
a[i] = saz[aa[i]];
b[i] = saz[bb[i]];
}
for (int i = 0; i < siz; i++) {
int x = v[i+1]-v[i];
for (int j = 1; j <= min(n,x); j++) {
int pro = 1;
for (int k = x, l = 1; k > x-j; k--, l++) pro = mul(pro, mul(k, inv[l]));
ch[j][i] = pro;
}
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= min(j,x); k++) {
c[j][i] = add(c[j][i], mul(ch[k][i], cho[j-1][k-1]));
}
}
}
for (int j = 0; j < siz; j++) {
for (int i = 0; i < n; i++) {
if (j) dp[i][j] = dp[i][j-1];
if (j < a[i] || j >= b[i]) continue;
int cnt = 1;
for (int k = i-1; k >= 0; k--) {
dp[i][j] = add(dp[i][j], mul(c[cnt][j], dp[k][j-1]));
cnt += (j >= a[k] && j < b[k]);
}
dp[i][j] = add(dp[i][j], c[cnt][j]);
}
}
int res = 0;
for (int i = 0; i < n; i++) res = add(res, dp[i][siz-1]);
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
423 ms |
7288 KB |
Output is correct |
2 |
Correct |
404 ms |
7288 KB |
Output is correct |
3 |
Correct |
439 ms |
7284 KB |
Output is correct |
4 |
Correct |
445 ms |
7304 KB |
Output is correct |
5 |
Correct |
410 ms |
7300 KB |
Output is correct |
6 |
Correct |
430 ms |
7508 KB |
Output is correct |
7 |
Correct |
443 ms |
7288 KB |
Output is correct |
8 |
Correct |
428 ms |
7288 KB |
Output is correct |
9 |
Correct |
443 ms |
7248 KB |
Output is correct |
10 |
Correct |
420 ms |
7252 KB |
Output is correct |
11 |
Correct |
409 ms |
7252 KB |
Output is correct |
12 |
Correct |
408 ms |
7264 KB |
Output is correct |
13 |
Correct |
427 ms |
7288 KB |
Output is correct |
14 |
Correct |
426 ms |
7288 KB |
Output is correct |
15 |
Correct |
422 ms |
7248 KB |
Output is correct |
16 |
Correct |
76 ms |
7248 KB |
Output is correct |
17 |
Correct |
88 ms |
7248 KB |
Output is correct |
18 |
Correct |
79 ms |
7248 KB |
Output is correct |
19 |
Correct |
80 ms |
7252 KB |
Output is correct |
20 |
Correct |
89 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
423 ms |
7288 KB |
Output is correct |
2 |
Correct |
404 ms |
7288 KB |
Output is correct |
3 |
Correct |
439 ms |
7284 KB |
Output is correct |
4 |
Correct |
445 ms |
7304 KB |
Output is correct |
5 |
Correct |
410 ms |
7300 KB |
Output is correct |
6 |
Correct |
430 ms |
7508 KB |
Output is correct |
7 |
Correct |
443 ms |
7288 KB |
Output is correct |
8 |
Correct |
428 ms |
7288 KB |
Output is correct |
9 |
Correct |
443 ms |
7248 KB |
Output is correct |
10 |
Correct |
420 ms |
7252 KB |
Output is correct |
11 |
Correct |
409 ms |
7252 KB |
Output is correct |
12 |
Correct |
408 ms |
7264 KB |
Output is correct |
13 |
Correct |
427 ms |
7288 KB |
Output is correct |
14 |
Correct |
426 ms |
7288 KB |
Output is correct |
15 |
Correct |
422 ms |
7248 KB |
Output is correct |
16 |
Correct |
76 ms |
7248 KB |
Output is correct |
17 |
Correct |
88 ms |
7248 KB |
Output is correct |
18 |
Correct |
79 ms |
7248 KB |
Output is correct |
19 |
Correct |
80 ms |
7252 KB |
Output is correct |
20 |
Correct |
89 ms |
7248 KB |
Output is correct |
21 |
Correct |
117 ms |
7260 KB |
Output is correct |
22 |
Correct |
115 ms |
7256 KB |
Output is correct |
23 |
Correct |
107 ms |
7472 KB |
Output is correct |
24 |
Correct |
114 ms |
7464 KB |
Output is correct |
25 |
Correct |
110 ms |
7260 KB |
Output is correct |
26 |
Correct |
157 ms |
7464 KB |
Output is correct |
27 |
Correct |
171 ms |
7260 KB |
Output is correct |
28 |
Correct |
168 ms |
7260 KB |
Output is correct |
29 |
Correct |
160 ms |
7256 KB |
Output is correct |
30 |
Correct |
384 ms |
7284 KB |
Output is correct |
31 |
Correct |
380 ms |
7252 KB |
Output is correct |
32 |
Correct |
363 ms |
7252 KB |
Output is correct |
33 |
Correct |
374 ms |
7248 KB |
Output is correct |
34 |
Correct |
377 ms |
7300 KB |
Output is correct |
35 |
Correct |
363 ms |
7248 KB |
Output is correct |
36 |
Correct |
381 ms |
7396 KB |
Output is correct |
37 |
Correct |
359 ms |
7284 KB |
Output is correct |
38 |
Correct |
348 ms |
7292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2652 KB |
Output is correct |
2 |
Correct |
9 ms |
2544 KB |
Output is correct |
3 |
Correct |
8 ms |
2648 KB |
Output is correct |
4 |
Correct |
8 ms |
2652 KB |
Output is correct |
5 |
Correct |
9 ms |
2548 KB |
Output is correct |
6 |
Correct |
10 ms |
2704 KB |
Output is correct |
7 |
Correct |
10 ms |
2652 KB |
Output is correct |
8 |
Correct |
9 ms |
2652 KB |
Output is correct |
9 |
Correct |
8 ms |
2652 KB |
Output is correct |
10 |
Correct |
9 ms |
2556 KB |
Output is correct |
11 |
Correct |
8 ms |
2552 KB |
Output is correct |
12 |
Correct |
9 ms |
2544 KB |
Output is correct |
13 |
Correct |
9 ms |
2648 KB |
Output is correct |
14 |
Correct |
8 ms |
2652 KB |
Output is correct |
15 |
Correct |
9 ms |
2652 KB |
Output is correct |
16 |
Correct |
5 ms |
2648 KB |
Output is correct |
17 |
Correct |
5 ms |
2652 KB |
Output is correct |
18 |
Correct |
5 ms |
2652 KB |
Output is correct |
19 |
Correct |
5 ms |
2536 KB |
Output is correct |
20 |
Correct |
5 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
423 ms |
7288 KB |
Output is correct |
2 |
Correct |
404 ms |
7288 KB |
Output is correct |
3 |
Correct |
439 ms |
7284 KB |
Output is correct |
4 |
Correct |
445 ms |
7304 KB |
Output is correct |
5 |
Correct |
410 ms |
7300 KB |
Output is correct |
6 |
Correct |
430 ms |
7508 KB |
Output is correct |
7 |
Correct |
443 ms |
7288 KB |
Output is correct |
8 |
Correct |
428 ms |
7288 KB |
Output is correct |
9 |
Correct |
443 ms |
7248 KB |
Output is correct |
10 |
Correct |
420 ms |
7252 KB |
Output is correct |
11 |
Correct |
409 ms |
7252 KB |
Output is correct |
12 |
Correct |
408 ms |
7264 KB |
Output is correct |
13 |
Correct |
427 ms |
7288 KB |
Output is correct |
14 |
Correct |
426 ms |
7288 KB |
Output is correct |
15 |
Correct |
422 ms |
7248 KB |
Output is correct |
16 |
Correct |
76 ms |
7248 KB |
Output is correct |
17 |
Correct |
88 ms |
7248 KB |
Output is correct |
18 |
Correct |
79 ms |
7248 KB |
Output is correct |
19 |
Correct |
80 ms |
7252 KB |
Output is correct |
20 |
Correct |
89 ms |
7248 KB |
Output is correct |
21 |
Correct |
117 ms |
7260 KB |
Output is correct |
22 |
Correct |
115 ms |
7256 KB |
Output is correct |
23 |
Correct |
107 ms |
7472 KB |
Output is correct |
24 |
Correct |
114 ms |
7464 KB |
Output is correct |
25 |
Correct |
110 ms |
7260 KB |
Output is correct |
26 |
Correct |
157 ms |
7464 KB |
Output is correct |
27 |
Correct |
171 ms |
7260 KB |
Output is correct |
28 |
Correct |
168 ms |
7260 KB |
Output is correct |
29 |
Correct |
160 ms |
7256 KB |
Output is correct |
30 |
Correct |
384 ms |
7284 KB |
Output is correct |
31 |
Correct |
380 ms |
7252 KB |
Output is correct |
32 |
Correct |
363 ms |
7252 KB |
Output is correct |
33 |
Correct |
374 ms |
7248 KB |
Output is correct |
34 |
Correct |
377 ms |
7300 KB |
Output is correct |
35 |
Correct |
363 ms |
7248 KB |
Output is correct |
36 |
Correct |
381 ms |
7396 KB |
Output is correct |
37 |
Correct |
359 ms |
7284 KB |
Output is correct |
38 |
Correct |
348 ms |
7292 KB |
Output is correct |
39 |
Correct |
9 ms |
2652 KB |
Output is correct |
40 |
Correct |
9 ms |
2544 KB |
Output is correct |
41 |
Correct |
8 ms |
2648 KB |
Output is correct |
42 |
Correct |
8 ms |
2652 KB |
Output is correct |
43 |
Correct |
9 ms |
2548 KB |
Output is correct |
44 |
Correct |
10 ms |
2704 KB |
Output is correct |
45 |
Correct |
10 ms |
2652 KB |
Output is correct |
46 |
Correct |
9 ms |
2652 KB |
Output is correct |
47 |
Correct |
8 ms |
2652 KB |
Output is correct |
48 |
Correct |
9 ms |
2556 KB |
Output is correct |
49 |
Correct |
8 ms |
2552 KB |
Output is correct |
50 |
Correct |
9 ms |
2544 KB |
Output is correct |
51 |
Correct |
9 ms |
2648 KB |
Output is correct |
52 |
Correct |
8 ms |
2652 KB |
Output is correct |
53 |
Correct |
9 ms |
2652 KB |
Output is correct |
54 |
Correct |
5 ms |
2648 KB |
Output is correct |
55 |
Correct |
5 ms |
2652 KB |
Output is correct |
56 |
Correct |
5 ms |
2652 KB |
Output is correct |
57 |
Correct |
5 ms |
2536 KB |
Output is correct |
58 |
Correct |
5 ms |
2652 KB |
Output is correct |
59 |
Correct |
857 ms |
7284 KB |
Output is correct |
60 |
Correct |
901 ms |
7504 KB |
Output is correct |
61 |
Correct |
849 ms |
7504 KB |
Output is correct |
62 |
Correct |
939 ms |
7508 KB |
Output is correct |
63 |
Correct |
906 ms |
7292 KB |
Output is correct |
64 |
Correct |
1002 ms |
7248 KB |
Output is correct |
65 |
Correct |
984 ms |
7288 KB |
Output is correct |
66 |
Correct |
997 ms |
7504 KB |
Output is correct |
67 |
Correct |
995 ms |
7288 KB |
Output is correct |
68 |
Correct |
965 ms |
7504 KB |
Output is correct |
69 |
Correct |
931 ms |
7504 KB |
Output is correct |
70 |
Correct |
923 ms |
7284 KB |
Output is correct |
71 |
Correct |
909 ms |
7288 KB |
Output is correct |
72 |
Correct |
970 ms |
7292 KB |
Output is correct |
73 |
Correct |
990 ms |
7484 KB |
Output is correct |
74 |
Correct |
115 ms |
7248 KB |
Output is correct |
75 |
Correct |
119 ms |
7252 KB |
Output is correct |
76 |
Correct |
112 ms |
7268 KB |
Output is correct |
77 |
Correct |
116 ms |
7252 KB |
Output is correct |
78 |
Correct |
108 ms |
7252 KB |
Output is correct |