# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255699 | 2020-08-01T15:33:13 Z | Mercenary | Boat (APIO16_boat) | C++14 | 581 ms | 4476 KB |
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef double ld; typedef pair<int,int> ii; typedef tree <ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 500 + 5; const int mod = 1e9 + 7; int n , a[maxn] , b[maxn]; int dp[maxn][maxn * 2]; int c[maxn * 2][maxn]; vector<int> val; int Pow(int i , int j){ if(j == 0)return 1; int r = Pow(i , j / 2); if(j & 1)return (ll)r * r % mod * i % mod; return (ll)r * r % mod; } int r[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n; for(int i = 1 ; i <= n ; ++i){ cin >> a[i] >> b[i];--a[i]; val.pb(a[i]);val.pb(b[i]); r[i] = Pow(i , mod - 2); } sort(val.begin(),val.end());val.erase(unique(val.begin(),val.end()),val.end()); for(int i = 0 ; i < val.size() ; ++i){ dp[0][i] = 1; if(i > 0){ int len = val[i] - val[i - 1]; c[i][0] = 1; for(int j = 1 ; j <= n ; ++j){ c[i][j] = (ll)c[i][j - 1] * (len + j - 1) % mod * r[j] % mod; } } } for(int i = 1 ; i <= n ; ++i){ dp[i][0] = 1; for(int j = 1 ; j < val.size() ; ++j){ int sum = 0; dp[i][j] = dp[i][j - 1]; for(int k = i ; k >= 1 ; --k){ if(a[k] < val[j] && val[j] <= b[k]){ dp[i][j] = (dp[i][j] + (ll)dp[k - 1][j - 1] * c[j][++sum]) %mod; } } // cout << dp[i][j] << " "; } // cout << endl; } cout << dp[n][val.size() - 1] - 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 259 ms | 4344 KB | Output is correct |
2 | Correct | 249 ms | 4300 KB | Output is correct |
3 | Correct | 247 ms | 4344 KB | Output is correct |
4 | Correct | 251 ms | 4476 KB | Output is correct |
5 | Correct | 245 ms | 4344 KB | Output is correct |
6 | Correct | 158 ms | 4344 KB | Output is correct |
7 | Correct | 153 ms | 4472 KB | Output is correct |
8 | Correct | 155 ms | 4344 KB | Output is correct |
9 | Correct | 174 ms | 4344 KB | Output is correct |
10 | Correct | 154 ms | 4344 KB | Output is correct |
11 | Correct | 155 ms | 4476 KB | Output is correct |
12 | Correct | 160 ms | 4344 KB | Output is correct |
13 | Correct | 150 ms | 4344 KB | Output is correct |
14 | Correct | 152 ms | 4344 KB | Output is correct |
15 | Correct | 166 ms | 4344 KB | Output is correct |
16 | Correct | 52 ms | 2680 KB | Output is correct |
17 | Correct | 53 ms | 2680 KB | Output is correct |
18 | Correct | 53 ms | 2680 KB | Output is correct |
19 | Correct | 55 ms | 2712 KB | Output is correct |
20 | Correct | 58 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 259 ms | 4344 KB | Output is correct |
2 | Correct | 249 ms | 4300 KB | Output is correct |
3 | Correct | 247 ms | 4344 KB | Output is correct |
4 | Correct | 251 ms | 4476 KB | Output is correct |
5 | Correct | 245 ms | 4344 KB | Output is correct |
6 | Correct | 158 ms | 4344 KB | Output is correct |
7 | Correct | 153 ms | 4472 KB | Output is correct |
8 | Correct | 155 ms | 4344 KB | Output is correct |
9 | Correct | 174 ms | 4344 KB | Output is correct |
10 | Correct | 154 ms | 4344 KB | Output is correct |
11 | Correct | 155 ms | 4476 KB | Output is correct |
12 | Correct | 160 ms | 4344 KB | Output is correct |
13 | Correct | 150 ms | 4344 KB | Output is correct |
14 | Correct | 152 ms | 4344 KB | Output is correct |
15 | Correct | 166 ms | 4344 KB | Output is correct |
16 | Correct | 52 ms | 2680 KB | Output is correct |
17 | Correct | 53 ms | 2680 KB | Output is correct |
18 | Correct | 53 ms | 2680 KB | Output is correct |
19 | Correct | 55 ms | 2712 KB | Output is correct |
20 | Correct | 58 ms | 2680 KB | Output is correct |
21 | Correct | 369 ms | 4188 KB | Output is correct |
22 | Correct | 367 ms | 4144 KB | Output is correct |
23 | Correct | 351 ms | 4084 KB | Output is correct |
24 | Correct | 358 ms | 4088 KB | Output is correct |
25 | Correct | 376 ms | 4216 KB | Output is correct |
26 | Correct | 486 ms | 4088 KB | Output is correct |
27 | Correct | 496 ms | 4180 KB | Output is correct |
28 | Correct | 479 ms | 4088 KB | Output is correct |
29 | Correct | 478 ms | 4088 KB | Output is correct |
30 | Correct | 164 ms | 4344 KB | Output is correct |
31 | Correct | 152 ms | 4344 KB | Output is correct |
32 | Correct | 153 ms | 4344 KB | Output is correct |
33 | Correct | 150 ms | 4344 KB | Output is correct |
34 | Correct | 156 ms | 4472 KB | Output is correct |
35 | Correct | 265 ms | 4344 KB | Output is correct |
36 | Correct | 260 ms | 4344 KB | Output is correct |
37 | Correct | 256 ms | 4472 KB | Output is correct |
38 | Correct | 259 ms | 4344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1152 KB | Output is correct |
2 | Correct | 4 ms | 1152 KB | Output is correct |
3 | Correct | 4 ms | 1152 KB | Output is correct |
4 | Correct | 4 ms | 1152 KB | Output is correct |
5 | Correct | 4 ms | 1152 KB | Output is correct |
6 | Correct | 5 ms | 1152 KB | Output is correct |
7 | Correct | 5 ms | 1152 KB | Output is correct |
8 | Correct | 5 ms | 1152 KB | Output is correct |
9 | Correct | 5 ms | 1152 KB | Output is correct |
10 | Correct | 5 ms | 1152 KB | Output is correct |
11 | Correct | 5 ms | 1152 KB | Output is correct |
12 | Correct | 4 ms | 1152 KB | Output is correct |
13 | Correct | 5 ms | 1152 KB | Output is correct |
14 | Correct | 5 ms | 1152 KB | Output is correct |
15 | Correct | 6 ms | 1152 KB | Output is correct |
16 | Correct | 3 ms | 1024 KB | Output is correct |
17 | Correct | 3 ms | 1024 KB | Output is correct |
18 | Correct | 3 ms | 1024 KB | Output is correct |
19 | Correct | 3 ms | 1024 KB | Output is correct |
20 | Correct | 3 ms | 1024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 259 ms | 4344 KB | Output is correct |
2 | Correct | 249 ms | 4300 KB | Output is correct |
3 | Correct | 247 ms | 4344 KB | Output is correct |
4 | Correct | 251 ms | 4476 KB | Output is correct |
5 | Correct | 245 ms | 4344 KB | Output is correct |
6 | Correct | 158 ms | 4344 KB | Output is correct |
7 | Correct | 153 ms | 4472 KB | Output is correct |
8 | Correct | 155 ms | 4344 KB | Output is correct |
9 | Correct | 174 ms | 4344 KB | Output is correct |
10 | Correct | 154 ms | 4344 KB | Output is correct |
11 | Correct | 155 ms | 4476 KB | Output is correct |
12 | Correct | 160 ms | 4344 KB | Output is correct |
13 | Correct | 150 ms | 4344 KB | Output is correct |
14 | Correct | 152 ms | 4344 KB | Output is correct |
15 | Correct | 166 ms | 4344 KB | Output is correct |
16 | Correct | 52 ms | 2680 KB | Output is correct |
17 | Correct | 53 ms | 2680 KB | Output is correct |
18 | Correct | 53 ms | 2680 KB | Output is correct |
19 | Correct | 55 ms | 2712 KB | Output is correct |
20 | Correct | 58 ms | 2680 KB | Output is correct |
21 | Correct | 369 ms | 4188 KB | Output is correct |
22 | Correct | 367 ms | 4144 KB | Output is correct |
23 | Correct | 351 ms | 4084 KB | Output is correct |
24 | Correct | 358 ms | 4088 KB | Output is correct |
25 | Correct | 376 ms | 4216 KB | Output is correct |
26 | Correct | 486 ms | 4088 KB | Output is correct |
27 | Correct | 496 ms | 4180 KB | Output is correct |
28 | Correct | 479 ms | 4088 KB | Output is correct |
29 | Correct | 478 ms | 4088 KB | Output is correct |
30 | Correct | 164 ms | 4344 KB | Output is correct |
31 | Correct | 152 ms | 4344 KB | Output is correct |
32 | Correct | 153 ms | 4344 KB | Output is correct |
33 | Correct | 150 ms | 4344 KB | Output is correct |
34 | Correct | 156 ms | 4472 KB | Output is correct |
35 | Correct | 265 ms | 4344 KB | Output is correct |
36 | Correct | 260 ms | 4344 KB | Output is correct |
37 | Correct | 256 ms | 4472 KB | Output is correct |
38 | Correct | 259 ms | 4344 KB | Output is correct |
39 | Correct | 4 ms | 1152 KB | Output is correct |
40 | Correct | 4 ms | 1152 KB | Output is correct |
41 | Correct | 4 ms | 1152 KB | Output is correct |
42 | Correct | 4 ms | 1152 KB | Output is correct |
43 | Correct | 4 ms | 1152 KB | Output is correct |
44 | Correct | 5 ms | 1152 KB | Output is correct |
45 | Correct | 5 ms | 1152 KB | Output is correct |
46 | Correct | 5 ms | 1152 KB | Output is correct |
47 | Correct | 5 ms | 1152 KB | Output is correct |
48 | Correct | 5 ms | 1152 KB | Output is correct |
49 | Correct | 5 ms | 1152 KB | Output is correct |
50 | Correct | 4 ms | 1152 KB | Output is correct |
51 | Correct | 5 ms | 1152 KB | Output is correct |
52 | Correct | 5 ms | 1152 KB | Output is correct |
53 | Correct | 6 ms | 1152 KB | Output is correct |
54 | Correct | 3 ms | 1024 KB | Output is correct |
55 | Correct | 3 ms | 1024 KB | Output is correct |
56 | Correct | 3 ms | 1024 KB | Output is correct |
57 | Correct | 3 ms | 1024 KB | Output is correct |
58 | Correct | 3 ms | 1024 KB | Output is correct |
59 | Correct | 406 ms | 4348 KB | Output is correct |
60 | Correct | 395 ms | 4344 KB | Output is correct |
61 | Correct | 390 ms | 4344 KB | Output is correct |
62 | Correct | 419 ms | 4368 KB | Output is correct |
63 | Correct | 395 ms | 4252 KB | Output is correct |
64 | Correct | 581 ms | 4344 KB | Output is correct |
65 | Correct | 551 ms | 4344 KB | Output is correct |
66 | Correct | 547 ms | 4344 KB | Output is correct |
67 | Correct | 551 ms | 4472 KB | Output is correct |
68 | Correct | 550 ms | 4344 KB | Output is correct |
69 | Correct | 421 ms | 4320 KB | Output is correct |
70 | Correct | 444 ms | 4344 KB | Output is correct |
71 | Correct | 439 ms | 4472 KB | Output is correct |
72 | Correct | 440 ms | 4344 KB | Output is correct |
73 | Correct | 439 ms | 4344 KB | Output is correct |
74 | Correct | 84 ms | 2684 KB | Output is correct |
75 | Correct | 87 ms | 2680 KB | Output is correct |
76 | Correct | 84 ms | 2728 KB | Output is correct |
77 | Correct | 86 ms | 2680 KB | Output is correct |
78 | Correct | 87 ms | 2808 KB | Output is correct |