# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
599620 |
2022-07-19T17:04:07 Z |
cadmiumsky |
Boat (APIO16_boat) |
C++14 |
|
688 ms |
444 KB |
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
const int nmax = 5e2 + 5, mod = 1e9 + 7;
ll inv[nmax];
int active[nmax], dp[nmax], tmpdp[nmax];
int main() {
inv[1] = 1;
for(int i = 2; i < nmax; i++) {
inv[i] = inv[mod % i] * (mod - mod / i) % mod;
}
vector<pair<int,int>> events;
vector<int> pos;
int n;
cin >> n;
for(int l, r, i = 1; i <= n; i++) {
cin >> l >> r;
events.emplace_back(l, i);
events.emplace_back(r + 1, -i);
pos.push_back(l);
pos.push_back(r + 1);
}
sort(all(events));
sort(all(pos));
pos.resize(unique(all(pos)) - pos.begin());
dp[0] = 1;
int ptr = 0, last = 0;
for(auto poz : pos) {
int dt = poz - last;
for(int i = 0; i <= n; i++)
tmpdp[i] = 0;
for(int i = 0; i <= n; i++) {
ll accum = 1, high = dt - 1, cnt = 0;
for(int j = i + 1; j <= n; j++) {
if(active[j]) {
high++;
cnt++;
accum = accum * high % mod * inv[cnt] % mod;
tmpdp[j] = ((ll)tmpdp[j] + (ll)dp[i] * accum) % mod;
}
}
}
for(int i = 0; i <= n; i++)
dp[i] = (dp[i] + tmpdp[i]) % mod;
while(ptr < events.size() && events[ptr].first <= poz) {
int x = events[ptr].second;
active[abs(x)] += (x / abs(x));
ptr++;
}
//cerr << last << ' ' << poz << '\n';
//for(int i = 1; i <= n; i++)
//cerr << dp[i] << ' ';
//cerr << '\n';
//cerr << '\n';
last = poz;
}
int sum = 0;
for(int i = 1; i <= n; i++)
sum = (sum + dp[i]) % mod;
cout << sum << '\n';
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:51:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | while(ptr < events.size() && events[ptr].first <= poz) {
| ~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
212 KB |
Output is correct |
2 |
Correct |
94 ms |
320 KB |
Output is correct |
3 |
Correct |
93 ms |
312 KB |
Output is correct |
4 |
Correct |
100 ms |
212 KB |
Output is correct |
5 |
Correct |
94 ms |
316 KB |
Output is correct |
6 |
Correct |
97 ms |
316 KB |
Output is correct |
7 |
Correct |
99 ms |
316 KB |
Output is correct |
8 |
Correct |
93 ms |
320 KB |
Output is correct |
9 |
Correct |
95 ms |
316 KB |
Output is correct |
10 |
Correct |
96 ms |
332 KB |
Output is correct |
11 |
Correct |
95 ms |
320 KB |
Output is correct |
12 |
Correct |
96 ms |
320 KB |
Output is correct |
13 |
Correct |
94 ms |
212 KB |
Output is correct |
14 |
Correct |
93 ms |
316 KB |
Output is correct |
15 |
Correct |
93 ms |
312 KB |
Output is correct |
16 |
Correct |
22 ms |
212 KB |
Output is correct |
17 |
Correct |
24 ms |
340 KB |
Output is correct |
18 |
Correct |
19 ms |
212 KB |
Output is correct |
19 |
Correct |
21 ms |
444 KB |
Output is correct |
20 |
Correct |
20 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
212 KB |
Output is correct |
2 |
Correct |
94 ms |
320 KB |
Output is correct |
3 |
Correct |
93 ms |
312 KB |
Output is correct |
4 |
Correct |
100 ms |
212 KB |
Output is correct |
5 |
Correct |
94 ms |
316 KB |
Output is correct |
6 |
Correct |
97 ms |
316 KB |
Output is correct |
7 |
Correct |
99 ms |
316 KB |
Output is correct |
8 |
Correct |
93 ms |
320 KB |
Output is correct |
9 |
Correct |
95 ms |
316 KB |
Output is correct |
10 |
Correct |
96 ms |
332 KB |
Output is correct |
11 |
Correct |
95 ms |
320 KB |
Output is correct |
12 |
Correct |
96 ms |
320 KB |
Output is correct |
13 |
Correct |
94 ms |
212 KB |
Output is correct |
14 |
Correct |
93 ms |
316 KB |
Output is correct |
15 |
Correct |
93 ms |
312 KB |
Output is correct |
16 |
Correct |
22 ms |
212 KB |
Output is correct |
17 |
Correct |
24 ms |
340 KB |
Output is correct |
18 |
Correct |
19 ms |
212 KB |
Output is correct |
19 |
Correct |
21 ms |
444 KB |
Output is correct |
20 |
Correct |
20 ms |
336 KB |
Output is correct |
21 |
Correct |
430 ms |
308 KB |
Output is correct |
22 |
Correct |
425 ms |
312 KB |
Output is correct |
23 |
Correct |
387 ms |
316 KB |
Output is correct |
24 |
Correct |
417 ms |
212 KB |
Output is correct |
25 |
Correct |
408 ms |
312 KB |
Output is correct |
26 |
Correct |
601 ms |
312 KB |
Output is correct |
27 |
Correct |
610 ms |
332 KB |
Output is correct |
28 |
Correct |
599 ms |
332 KB |
Output is correct |
29 |
Correct |
590 ms |
320 KB |
Output is correct |
30 |
Correct |
101 ms |
212 KB |
Output is correct |
31 |
Correct |
102 ms |
316 KB |
Output is correct |
32 |
Correct |
97 ms |
312 KB |
Output is correct |
33 |
Correct |
99 ms |
212 KB |
Output is correct |
34 |
Correct |
97 ms |
320 KB |
Output is correct |
35 |
Correct |
102 ms |
316 KB |
Output is correct |
36 |
Correct |
100 ms |
212 KB |
Output is correct |
37 |
Correct |
98 ms |
316 KB |
Output is correct |
38 |
Correct |
98 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
312 KB |
Output is correct |
4 |
Correct |
5 ms |
212 KB |
Output is correct |
5 |
Correct |
4 ms |
312 KB |
Output is correct |
6 |
Correct |
6 ms |
324 KB |
Output is correct |
7 |
Correct |
7 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
212 KB |
Output is correct |
9 |
Correct |
7 ms |
212 KB |
Output is correct |
10 |
Correct |
6 ms |
212 KB |
Output is correct |
11 |
Correct |
4 ms |
212 KB |
Output is correct |
12 |
Correct |
4 ms |
308 KB |
Output is correct |
13 |
Correct |
4 ms |
212 KB |
Output is correct |
14 |
Correct |
4 ms |
212 KB |
Output is correct |
15 |
Correct |
4 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
312 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
308 KB |
Output is correct |
20 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
212 KB |
Output is correct |
2 |
Correct |
94 ms |
320 KB |
Output is correct |
3 |
Correct |
93 ms |
312 KB |
Output is correct |
4 |
Correct |
100 ms |
212 KB |
Output is correct |
5 |
Correct |
94 ms |
316 KB |
Output is correct |
6 |
Correct |
97 ms |
316 KB |
Output is correct |
7 |
Correct |
99 ms |
316 KB |
Output is correct |
8 |
Correct |
93 ms |
320 KB |
Output is correct |
9 |
Correct |
95 ms |
316 KB |
Output is correct |
10 |
Correct |
96 ms |
332 KB |
Output is correct |
11 |
Correct |
95 ms |
320 KB |
Output is correct |
12 |
Correct |
96 ms |
320 KB |
Output is correct |
13 |
Correct |
94 ms |
212 KB |
Output is correct |
14 |
Correct |
93 ms |
316 KB |
Output is correct |
15 |
Correct |
93 ms |
312 KB |
Output is correct |
16 |
Correct |
22 ms |
212 KB |
Output is correct |
17 |
Correct |
24 ms |
340 KB |
Output is correct |
18 |
Correct |
19 ms |
212 KB |
Output is correct |
19 |
Correct |
21 ms |
444 KB |
Output is correct |
20 |
Correct |
20 ms |
336 KB |
Output is correct |
21 |
Correct |
430 ms |
308 KB |
Output is correct |
22 |
Correct |
425 ms |
312 KB |
Output is correct |
23 |
Correct |
387 ms |
316 KB |
Output is correct |
24 |
Correct |
417 ms |
212 KB |
Output is correct |
25 |
Correct |
408 ms |
312 KB |
Output is correct |
26 |
Correct |
601 ms |
312 KB |
Output is correct |
27 |
Correct |
610 ms |
332 KB |
Output is correct |
28 |
Correct |
599 ms |
332 KB |
Output is correct |
29 |
Correct |
590 ms |
320 KB |
Output is correct |
30 |
Correct |
101 ms |
212 KB |
Output is correct |
31 |
Correct |
102 ms |
316 KB |
Output is correct |
32 |
Correct |
97 ms |
312 KB |
Output is correct |
33 |
Correct |
99 ms |
212 KB |
Output is correct |
34 |
Correct |
97 ms |
320 KB |
Output is correct |
35 |
Correct |
102 ms |
316 KB |
Output is correct |
36 |
Correct |
100 ms |
212 KB |
Output is correct |
37 |
Correct |
98 ms |
316 KB |
Output is correct |
38 |
Correct |
98 ms |
316 KB |
Output is correct |
39 |
Correct |
4 ms |
212 KB |
Output is correct |
40 |
Correct |
4 ms |
212 KB |
Output is correct |
41 |
Correct |
4 ms |
312 KB |
Output is correct |
42 |
Correct |
5 ms |
212 KB |
Output is correct |
43 |
Correct |
4 ms |
312 KB |
Output is correct |
44 |
Correct |
6 ms |
324 KB |
Output is correct |
45 |
Correct |
7 ms |
212 KB |
Output is correct |
46 |
Correct |
6 ms |
212 KB |
Output is correct |
47 |
Correct |
7 ms |
212 KB |
Output is correct |
48 |
Correct |
6 ms |
212 KB |
Output is correct |
49 |
Correct |
4 ms |
212 KB |
Output is correct |
50 |
Correct |
4 ms |
308 KB |
Output is correct |
51 |
Correct |
4 ms |
212 KB |
Output is correct |
52 |
Correct |
4 ms |
212 KB |
Output is correct |
53 |
Correct |
4 ms |
212 KB |
Output is correct |
54 |
Correct |
3 ms |
312 KB |
Output is correct |
55 |
Correct |
3 ms |
212 KB |
Output is correct |
56 |
Correct |
3 ms |
212 KB |
Output is correct |
57 |
Correct |
3 ms |
308 KB |
Output is correct |
58 |
Correct |
3 ms |
212 KB |
Output is correct |
59 |
Correct |
468 ms |
316 KB |
Output is correct |
60 |
Correct |
439 ms |
316 KB |
Output is correct |
61 |
Correct |
423 ms |
332 KB |
Output is correct |
62 |
Correct |
459 ms |
328 KB |
Output is correct |
63 |
Correct |
452 ms |
212 KB |
Output is correct |
64 |
Correct |
686 ms |
212 KB |
Output is correct |
65 |
Correct |
688 ms |
316 KB |
Output is correct |
66 |
Correct |
684 ms |
316 KB |
Output is correct |
67 |
Correct |
679 ms |
212 KB |
Output is correct |
68 |
Correct |
684 ms |
316 KB |
Output is correct |
69 |
Correct |
401 ms |
316 KB |
Output is correct |
70 |
Correct |
394 ms |
316 KB |
Output is correct |
71 |
Correct |
406 ms |
324 KB |
Output is correct |
72 |
Correct |
401 ms |
212 KB |
Output is correct |
73 |
Correct |
427 ms |
320 KB |
Output is correct |
74 |
Correct |
94 ms |
320 KB |
Output is correct |
75 |
Correct |
87 ms |
312 KB |
Output is correct |
76 |
Correct |
90 ms |
328 KB |
Output is correct |
77 |
Correct |
92 ms |
312 KB |
Output is correct |
78 |
Correct |
91 ms |
212 KB |
Output is correct |