# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
107713 |
2019-04-25T14:15:39 Z |
Minnakhmetov |
Boat (APIO16_boat) |
C++14 |
|
1226 ms |
5656 KB |
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(aaa) aaa.begin(), aaa.end()
#pragma warning(disable : 4996)
const int N = 505, MOD = 1e9 + 7;
int a[N], b[N], dp[N][N * 2], dp2[N * 2][N], c[N][N], c2[N];
int n;
ll bp(ll a, ll p) {
ll r = 1;
while (p > 0) {
if (p & 1)
r = r * a % MOD;
p >>= 1;
a = a * a % MOD;
}
return r;
}
void f(int& a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
}
//
//
//const int M1 = 1e3 + 5, N1 = 10;
//int dpb[N1][M1];
//
//int slow() {
// dpb[0][0] = 1;
// int q = 0;
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < M1; j++) {
// f(dpb[i + 1][j], dpb[i][j]);
// }
// for (int j = 1; j < M1; j++) {
// f(dpb[i][j], dpb[i][j - 1]);
// }
// for (int j = a[i]; j <= b[i]; j++) {
// f(dpb[i + 1][j], dpb[i][j - 1]);
// }
// }
//
// for (int j = 1; j < M1; j++) {
// f(dpb[n][j], dpb[n][j - 1]);
// }
//
// return dpb[n][M1 - 1] - 1;
//}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < N; i++) {
c[i][0] = 1;
}
for (int i = 1; i < N; i++) {
for (int j = 1; j < N; j++) {
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
}
}
cin >> n;
vector<int> v;
v.push_back(0);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
v.push_back(a[i]);
v.push_back(b[i] + 1);
}
sort(all(v));
v.erase(unique(all(v)), v.end());
int m = v.size() - 1;
for (int i = 1; i < m; i++) {
ll t = 1;
for (int j = 0; j <= n; j++) {
c2[j] = t;
t = t * (v[i + 1] - v[i] - j) % MOD * bp(j + 1, MOD - 2) % MOD;
}
for (int j = 1; j <= n; j++) {
for (int h = 1; h <= j; h++) {
dp2[i][j] = (dp2[i][j] + c[j - 1][h - 1] * (ll)c2[h]) % MOD;
}
}
}
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 1; j < m; j++) {
f(dp[i][j], dp[i][j - 1]);
int g = 0;
for (int k = i; k < n; k++) {
if (a[k] <= v[j] && b[k] >= v[j + 1] - 1) {
g++;
dp[k + 1][j] = (dp[k + 1][j] + dp[i][j - 1] * (ll)dp2[j][g]) % MOD;
}
}
}
}
int ans = 0;
for (int i = 1; i < m; i++) {
f(ans, dp[n][i]);
}
for (int i = 1; i < n; i++) {
f(ans, dp[i][m - 1]);
}
cout << ans;
//cout << "\n" << slow();
return 0;
}
Compilation message
boat.cpp:42:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable : 4996)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1008 ms |
5324 KB |
Output is correct |
2 |
Correct |
1016 ms |
5276 KB |
Output is correct |
3 |
Correct |
1038 ms |
5352 KB |
Output is correct |
4 |
Correct |
1004 ms |
5372 KB |
Output is correct |
5 |
Correct |
1045 ms |
5380 KB |
Output is correct |
6 |
Correct |
848 ms |
5340 KB |
Output is correct |
7 |
Correct |
836 ms |
5328 KB |
Output is correct |
8 |
Correct |
803 ms |
5296 KB |
Output is correct |
9 |
Correct |
815 ms |
5404 KB |
Output is correct |
10 |
Correct |
805 ms |
5452 KB |
Output is correct |
11 |
Correct |
805 ms |
5260 KB |
Output is correct |
12 |
Correct |
890 ms |
5348 KB |
Output is correct |
13 |
Correct |
898 ms |
5368 KB |
Output is correct |
14 |
Correct |
827 ms |
5368 KB |
Output is correct |
15 |
Correct |
805 ms |
5368 KB |
Output is correct |
16 |
Correct |
184 ms |
3752 KB |
Output is correct |
17 |
Correct |
197 ms |
3832 KB |
Output is correct |
18 |
Correct |
206 ms |
3704 KB |
Output is correct |
19 |
Correct |
195 ms |
3780 KB |
Output is correct |
20 |
Correct |
193 ms |
3656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1008 ms |
5324 KB |
Output is correct |
2 |
Correct |
1016 ms |
5276 KB |
Output is correct |
3 |
Correct |
1038 ms |
5352 KB |
Output is correct |
4 |
Correct |
1004 ms |
5372 KB |
Output is correct |
5 |
Correct |
1045 ms |
5380 KB |
Output is correct |
6 |
Correct |
848 ms |
5340 KB |
Output is correct |
7 |
Correct |
836 ms |
5328 KB |
Output is correct |
8 |
Correct |
803 ms |
5296 KB |
Output is correct |
9 |
Correct |
815 ms |
5404 KB |
Output is correct |
10 |
Correct |
805 ms |
5452 KB |
Output is correct |
11 |
Correct |
805 ms |
5260 KB |
Output is correct |
12 |
Correct |
890 ms |
5348 KB |
Output is correct |
13 |
Correct |
898 ms |
5368 KB |
Output is correct |
14 |
Correct |
827 ms |
5368 KB |
Output is correct |
15 |
Correct |
805 ms |
5368 KB |
Output is correct |
16 |
Correct |
184 ms |
3752 KB |
Output is correct |
17 |
Correct |
197 ms |
3832 KB |
Output is correct |
18 |
Correct |
206 ms |
3704 KB |
Output is correct |
19 |
Correct |
195 ms |
3780 KB |
Output is correct |
20 |
Correct |
193 ms |
3656 KB |
Output is correct |
21 |
Correct |
961 ms |
5156 KB |
Output is correct |
22 |
Correct |
1006 ms |
5240 KB |
Output is correct |
23 |
Correct |
990 ms |
5192 KB |
Output is correct |
24 |
Correct |
979 ms |
5240 KB |
Output is correct |
25 |
Correct |
1066 ms |
5152 KB |
Output is correct |
26 |
Correct |
1083 ms |
5176 KB |
Output is correct |
27 |
Correct |
1044 ms |
5160 KB |
Output is correct |
28 |
Correct |
1114 ms |
5260 KB |
Output is correct |
29 |
Correct |
1048 ms |
5168 KB |
Output is correct |
30 |
Correct |
863 ms |
5340 KB |
Output is correct |
31 |
Correct |
833 ms |
5496 KB |
Output is correct |
32 |
Correct |
838 ms |
5348 KB |
Output is correct |
33 |
Correct |
889 ms |
5368 KB |
Output is correct |
34 |
Correct |
826 ms |
5256 KB |
Output is correct |
35 |
Correct |
986 ms |
5624 KB |
Output is correct |
36 |
Correct |
1014 ms |
5484 KB |
Output is correct |
37 |
Correct |
1041 ms |
5364 KB |
Output is correct |
38 |
Correct |
1018 ms |
5364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
2204 KB |
Output is correct |
2 |
Correct |
15 ms |
2176 KB |
Output is correct |
3 |
Correct |
14 ms |
2176 KB |
Output is correct |
4 |
Correct |
16 ms |
2176 KB |
Output is correct |
5 |
Correct |
14 ms |
2176 KB |
Output is correct |
6 |
Correct |
18 ms |
2176 KB |
Output is correct |
7 |
Correct |
17 ms |
2176 KB |
Output is correct |
8 |
Correct |
17 ms |
2176 KB |
Output is correct |
9 |
Correct |
17 ms |
2176 KB |
Output is correct |
10 |
Correct |
17 ms |
2176 KB |
Output is correct |
11 |
Correct |
17 ms |
2176 KB |
Output is correct |
12 |
Correct |
16 ms |
2176 KB |
Output is correct |
13 |
Correct |
15 ms |
2152 KB |
Output is correct |
14 |
Correct |
15 ms |
2176 KB |
Output is correct |
15 |
Correct |
14 ms |
2176 KB |
Output is correct |
16 |
Correct |
11 ms |
1920 KB |
Output is correct |
17 |
Correct |
10 ms |
1920 KB |
Output is correct |
18 |
Correct |
10 ms |
1920 KB |
Output is correct |
19 |
Correct |
29 ms |
2048 KB |
Output is correct |
20 |
Correct |
11 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1008 ms |
5324 KB |
Output is correct |
2 |
Correct |
1016 ms |
5276 KB |
Output is correct |
3 |
Correct |
1038 ms |
5352 KB |
Output is correct |
4 |
Correct |
1004 ms |
5372 KB |
Output is correct |
5 |
Correct |
1045 ms |
5380 KB |
Output is correct |
6 |
Correct |
848 ms |
5340 KB |
Output is correct |
7 |
Correct |
836 ms |
5328 KB |
Output is correct |
8 |
Correct |
803 ms |
5296 KB |
Output is correct |
9 |
Correct |
815 ms |
5404 KB |
Output is correct |
10 |
Correct |
805 ms |
5452 KB |
Output is correct |
11 |
Correct |
805 ms |
5260 KB |
Output is correct |
12 |
Correct |
890 ms |
5348 KB |
Output is correct |
13 |
Correct |
898 ms |
5368 KB |
Output is correct |
14 |
Correct |
827 ms |
5368 KB |
Output is correct |
15 |
Correct |
805 ms |
5368 KB |
Output is correct |
16 |
Correct |
184 ms |
3752 KB |
Output is correct |
17 |
Correct |
197 ms |
3832 KB |
Output is correct |
18 |
Correct |
206 ms |
3704 KB |
Output is correct |
19 |
Correct |
195 ms |
3780 KB |
Output is correct |
20 |
Correct |
193 ms |
3656 KB |
Output is correct |
21 |
Correct |
961 ms |
5156 KB |
Output is correct |
22 |
Correct |
1006 ms |
5240 KB |
Output is correct |
23 |
Correct |
990 ms |
5192 KB |
Output is correct |
24 |
Correct |
979 ms |
5240 KB |
Output is correct |
25 |
Correct |
1066 ms |
5152 KB |
Output is correct |
26 |
Correct |
1083 ms |
5176 KB |
Output is correct |
27 |
Correct |
1044 ms |
5160 KB |
Output is correct |
28 |
Correct |
1114 ms |
5260 KB |
Output is correct |
29 |
Correct |
1048 ms |
5168 KB |
Output is correct |
30 |
Correct |
863 ms |
5340 KB |
Output is correct |
31 |
Correct |
833 ms |
5496 KB |
Output is correct |
32 |
Correct |
838 ms |
5348 KB |
Output is correct |
33 |
Correct |
889 ms |
5368 KB |
Output is correct |
34 |
Correct |
826 ms |
5256 KB |
Output is correct |
35 |
Correct |
986 ms |
5624 KB |
Output is correct |
36 |
Correct |
1014 ms |
5484 KB |
Output is correct |
37 |
Correct |
1041 ms |
5364 KB |
Output is correct |
38 |
Correct |
1018 ms |
5364 KB |
Output is correct |
39 |
Correct |
16 ms |
2204 KB |
Output is correct |
40 |
Correct |
15 ms |
2176 KB |
Output is correct |
41 |
Correct |
14 ms |
2176 KB |
Output is correct |
42 |
Correct |
16 ms |
2176 KB |
Output is correct |
43 |
Correct |
14 ms |
2176 KB |
Output is correct |
44 |
Correct |
18 ms |
2176 KB |
Output is correct |
45 |
Correct |
17 ms |
2176 KB |
Output is correct |
46 |
Correct |
17 ms |
2176 KB |
Output is correct |
47 |
Correct |
17 ms |
2176 KB |
Output is correct |
48 |
Correct |
17 ms |
2176 KB |
Output is correct |
49 |
Correct |
17 ms |
2176 KB |
Output is correct |
50 |
Correct |
16 ms |
2176 KB |
Output is correct |
51 |
Correct |
15 ms |
2152 KB |
Output is correct |
52 |
Correct |
15 ms |
2176 KB |
Output is correct |
53 |
Correct |
14 ms |
2176 KB |
Output is correct |
54 |
Correct |
11 ms |
1920 KB |
Output is correct |
55 |
Correct |
10 ms |
1920 KB |
Output is correct |
56 |
Correct |
10 ms |
1920 KB |
Output is correct |
57 |
Correct |
29 ms |
2048 KB |
Output is correct |
58 |
Correct |
11 ms |
1920 KB |
Output is correct |
59 |
Correct |
1100 ms |
5340 KB |
Output is correct |
60 |
Correct |
1030 ms |
5368 KB |
Output is correct |
61 |
Correct |
1058 ms |
5356 KB |
Output is correct |
62 |
Correct |
1010 ms |
5492 KB |
Output is correct |
63 |
Correct |
991 ms |
5444 KB |
Output is correct |
64 |
Correct |
1118 ms |
5468 KB |
Output is correct |
65 |
Correct |
1180 ms |
5572 KB |
Output is correct |
66 |
Correct |
1081 ms |
5360 KB |
Output is correct |
67 |
Correct |
1057 ms |
5496 KB |
Output is correct |
68 |
Correct |
1226 ms |
5404 KB |
Output is correct |
69 |
Correct |
996 ms |
5656 KB |
Output is correct |
70 |
Correct |
1060 ms |
5480 KB |
Output is correct |
71 |
Correct |
997 ms |
5524 KB |
Output is correct |
72 |
Correct |
1000 ms |
5368 KB |
Output is correct |
73 |
Correct |
1024 ms |
5424 KB |
Output is correct |
74 |
Correct |
221 ms |
3832 KB |
Output is correct |
75 |
Correct |
219 ms |
3824 KB |
Output is correct |
76 |
Correct |
234 ms |
3776 KB |
Output is correct |
77 |
Correct |
221 ms |
3704 KB |
Output is correct |
78 |
Correct |
200 ms |
3832 KB |
Output is correct |