# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
548341 |
2022-04-13T04:39:54 Z |
gimabd30 |
Boat (APIO16_boat) |
C++17 |
|
581 ms |
4432 KB |
//#define _GLIBCXX_DEBUG
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using normal_queue = priority_queue <T, vector<T>, greater<>>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define trace(x) cout << #x << ": " << (x) << endl;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define uniq(x) x.resize(unique(all(x)) - begin(x))
#define ld long double
#define sz(s) ((int) size(s))
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define int128 __int128
#define pb push_back
#define eb emplace_back
template<typename T>
bool ckmin(T &x, T y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template<typename T>
bool ckmax(T &x, T y) {
if (x < y) {
x = y;
return true;
}
return false;
}
int bit(int x, int b) {
return (x >> b) & 1;
}
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
//soryan za musor sverhu
const ll infL = 3e18;
const int infI = 1'000'000'000 + 7;
const int N = 1001;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
ll fastp(ll a, ll p) {
ll ans = 1;
a %= mod;
while (p) {
if (p & 1)
ans = ans * a % mod;
a = a * a % mod;
p >>= 1;
}
return ans;
}
ll fac[N];
ll invfac[N];
ll invnum[N];
void init() {
int n = N - 1;
fac[0] = invnum[0] = invfac[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = fac[i - 1] * i % mod;
}
invfac[n] = fastp(fac[n], mod - 2);
invnum[n] = invfac[n] * fac[n - 1] % mod;
for (int i = n - 1; i > 0; --i) {
invfac[i] = invfac[i + 1] * (i + 1) % mod;
invnum[i] = invfac[i] * fac[i - 1] % mod;
}
}
ll inv(ll a) {
if (a < N) return invnum[a];
return fastp(a, mod - 2);
}
ll cnk(int n, int k) {
if (k < 0 || k > n) return 0;
return fac[n] * invfac[n - k] % mod * invfac[k] % mod;
}
ll dp[N][N];
int A[N], B[N], cord[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> A[i] >> B[i];
++B[i];
cord[(i - 1) * 2] = A[i];
cord[(i - 1) * 2 + 1] = B[i];
}
sort(cord, cord + n * 2);
int m = unique(cord, cord + 2 * n) - cord;
for (int i = 1; i <= n; ++i) {
A[i] = lower_bound(cord, cord + m, A[i]) - cord + 1;
B[i] = lower_bound(cord, cord + m, B[i]) - cord + 1;
}
for (int i = 0; i < m; ++i) dp[0][i] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = A[i]; j < B[i]; ++j) {
ll len = cord[j] - cord[j - 1];
ll x = len;
int cnt = 1;
//this number is C(len + cnt - 1, cnt - 1)
//so when we increase cnt, x = x * (len + cnt - 1) / cnt
//because the last one is 100% not zero
for (int k = i - 1; k >= 0; --k) {
dp[i][j] = (dp[i][j] + x * dp[k][j - 1]) % mod;
if (A[k] <= j && j < B[k]) {
++cnt;
x = x * (len + cnt - 1) % mod * inv(cnt) % mod;
}
}
}
for (int j = 1; j < N; ++j) {
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
}
ll ans = 0;
for (int i = 1; i <= n; ++i) {
ans = (ans + dp[i][N - 1]) % mod;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4296 KB |
Output is correct |
3 |
Correct |
7 ms |
4180 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
7 ms |
4268 KB |
Output is correct |
6 |
Correct |
7 ms |
4180 KB |
Output is correct |
7 |
Correct |
7 ms |
4176 KB |
Output is correct |
8 |
Correct |
7 ms |
4220 KB |
Output is correct |
9 |
Correct |
6 ms |
4180 KB |
Output is correct |
10 |
Correct |
7 ms |
4180 KB |
Output is correct |
11 |
Correct |
7 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4180 KB |
Output is correct |
14 |
Correct |
7 ms |
4180 KB |
Output is correct |
15 |
Correct |
7 ms |
4308 KB |
Output is correct |
16 |
Correct |
7 ms |
4200 KB |
Output is correct |
17 |
Correct |
8 ms |
4180 KB |
Output is correct |
18 |
Correct |
7 ms |
4180 KB |
Output is correct |
19 |
Correct |
7 ms |
4180 KB |
Output is correct |
20 |
Correct |
7 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4296 KB |
Output is correct |
3 |
Correct |
7 ms |
4180 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
7 ms |
4268 KB |
Output is correct |
6 |
Correct |
7 ms |
4180 KB |
Output is correct |
7 |
Correct |
7 ms |
4176 KB |
Output is correct |
8 |
Correct |
7 ms |
4220 KB |
Output is correct |
9 |
Correct |
6 ms |
4180 KB |
Output is correct |
10 |
Correct |
7 ms |
4180 KB |
Output is correct |
11 |
Correct |
7 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4180 KB |
Output is correct |
14 |
Correct |
7 ms |
4180 KB |
Output is correct |
15 |
Correct |
7 ms |
4308 KB |
Output is correct |
16 |
Correct |
7 ms |
4200 KB |
Output is correct |
17 |
Correct |
8 ms |
4180 KB |
Output is correct |
18 |
Correct |
7 ms |
4180 KB |
Output is correct |
19 |
Correct |
7 ms |
4180 KB |
Output is correct |
20 |
Correct |
7 ms |
4180 KB |
Output is correct |
21 |
Correct |
240 ms |
4204 KB |
Output is correct |
22 |
Correct |
232 ms |
4184 KB |
Output is correct |
23 |
Correct |
237 ms |
4212 KB |
Output is correct |
24 |
Correct |
230 ms |
4260 KB |
Output is correct |
25 |
Correct |
243 ms |
4312 KB |
Output is correct |
26 |
Correct |
483 ms |
4212 KB |
Output is correct |
27 |
Correct |
514 ms |
4284 KB |
Output is correct |
28 |
Correct |
499 ms |
4180 KB |
Output is correct |
29 |
Correct |
497 ms |
4396 KB |
Output is correct |
30 |
Correct |
8 ms |
4180 KB |
Output is correct |
31 |
Correct |
8 ms |
4212 KB |
Output is correct |
32 |
Correct |
9 ms |
4204 KB |
Output is correct |
33 |
Correct |
8 ms |
4208 KB |
Output is correct |
34 |
Correct |
10 ms |
4356 KB |
Output is correct |
35 |
Correct |
10 ms |
4256 KB |
Output is correct |
36 |
Correct |
11 ms |
4204 KB |
Output is correct |
37 |
Correct |
8 ms |
4432 KB |
Output is correct |
38 |
Correct |
8 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1124 KB |
Output is correct |
3 |
Correct |
4 ms |
1108 KB |
Output is correct |
4 |
Correct |
4 ms |
1108 KB |
Output is correct |
5 |
Correct |
4 ms |
1116 KB |
Output is correct |
6 |
Correct |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
6 ms |
1120 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
7 ms |
1080 KB |
Output is correct |
10 |
Correct |
6 ms |
1120 KB |
Output is correct |
11 |
Correct |
4 ms |
1124 KB |
Output is correct |
12 |
Correct |
3 ms |
1124 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
3 ms |
1108 KB |
Output is correct |
15 |
Correct |
4 ms |
1108 KB |
Output is correct |
16 |
Correct |
3 ms |
1044 KB |
Output is correct |
17 |
Correct |
3 ms |
1236 KB |
Output is correct |
18 |
Correct |
3 ms |
1108 KB |
Output is correct |
19 |
Correct |
3 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4296 KB |
Output is correct |
3 |
Correct |
7 ms |
4180 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
7 ms |
4268 KB |
Output is correct |
6 |
Correct |
7 ms |
4180 KB |
Output is correct |
7 |
Correct |
7 ms |
4176 KB |
Output is correct |
8 |
Correct |
7 ms |
4220 KB |
Output is correct |
9 |
Correct |
6 ms |
4180 KB |
Output is correct |
10 |
Correct |
7 ms |
4180 KB |
Output is correct |
11 |
Correct |
7 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4180 KB |
Output is correct |
13 |
Correct |
6 ms |
4180 KB |
Output is correct |
14 |
Correct |
7 ms |
4180 KB |
Output is correct |
15 |
Correct |
7 ms |
4308 KB |
Output is correct |
16 |
Correct |
7 ms |
4200 KB |
Output is correct |
17 |
Correct |
8 ms |
4180 KB |
Output is correct |
18 |
Correct |
7 ms |
4180 KB |
Output is correct |
19 |
Correct |
7 ms |
4180 KB |
Output is correct |
20 |
Correct |
7 ms |
4180 KB |
Output is correct |
21 |
Correct |
240 ms |
4204 KB |
Output is correct |
22 |
Correct |
232 ms |
4184 KB |
Output is correct |
23 |
Correct |
237 ms |
4212 KB |
Output is correct |
24 |
Correct |
230 ms |
4260 KB |
Output is correct |
25 |
Correct |
243 ms |
4312 KB |
Output is correct |
26 |
Correct |
483 ms |
4212 KB |
Output is correct |
27 |
Correct |
514 ms |
4284 KB |
Output is correct |
28 |
Correct |
499 ms |
4180 KB |
Output is correct |
29 |
Correct |
497 ms |
4396 KB |
Output is correct |
30 |
Correct |
8 ms |
4180 KB |
Output is correct |
31 |
Correct |
8 ms |
4212 KB |
Output is correct |
32 |
Correct |
9 ms |
4204 KB |
Output is correct |
33 |
Correct |
8 ms |
4208 KB |
Output is correct |
34 |
Correct |
10 ms |
4356 KB |
Output is correct |
35 |
Correct |
10 ms |
4256 KB |
Output is correct |
36 |
Correct |
11 ms |
4204 KB |
Output is correct |
37 |
Correct |
8 ms |
4432 KB |
Output is correct |
38 |
Correct |
8 ms |
4180 KB |
Output is correct |
39 |
Correct |
4 ms |
1108 KB |
Output is correct |
40 |
Correct |
3 ms |
1124 KB |
Output is correct |
41 |
Correct |
4 ms |
1108 KB |
Output is correct |
42 |
Correct |
4 ms |
1108 KB |
Output is correct |
43 |
Correct |
4 ms |
1116 KB |
Output is correct |
44 |
Correct |
6 ms |
1108 KB |
Output is correct |
45 |
Correct |
6 ms |
1120 KB |
Output is correct |
46 |
Correct |
6 ms |
1108 KB |
Output is correct |
47 |
Correct |
7 ms |
1080 KB |
Output is correct |
48 |
Correct |
6 ms |
1120 KB |
Output is correct |
49 |
Correct |
4 ms |
1124 KB |
Output is correct |
50 |
Correct |
3 ms |
1124 KB |
Output is correct |
51 |
Correct |
4 ms |
1108 KB |
Output is correct |
52 |
Correct |
3 ms |
1108 KB |
Output is correct |
53 |
Correct |
4 ms |
1108 KB |
Output is correct |
54 |
Correct |
3 ms |
1044 KB |
Output is correct |
55 |
Correct |
3 ms |
1236 KB |
Output is correct |
56 |
Correct |
3 ms |
1108 KB |
Output is correct |
57 |
Correct |
3 ms |
1108 KB |
Output is correct |
58 |
Correct |
3 ms |
1124 KB |
Output is correct |
59 |
Correct |
279 ms |
4428 KB |
Output is correct |
60 |
Correct |
262 ms |
4340 KB |
Output is correct |
61 |
Correct |
231 ms |
4236 KB |
Output is correct |
62 |
Correct |
313 ms |
4272 KB |
Output is correct |
63 |
Correct |
282 ms |
4220 KB |
Output is correct |
64 |
Correct |
581 ms |
4312 KB |
Output is correct |
65 |
Correct |
573 ms |
4280 KB |
Output is correct |
66 |
Correct |
547 ms |
4188 KB |
Output is correct |
67 |
Correct |
556 ms |
4320 KB |
Output is correct |
68 |
Correct |
560 ms |
4236 KB |
Output is correct |
69 |
Correct |
223 ms |
4236 KB |
Output is correct |
70 |
Correct |
227 ms |
4240 KB |
Output is correct |
71 |
Correct |
233 ms |
4296 KB |
Output is correct |
72 |
Correct |
244 ms |
4280 KB |
Output is correct |
73 |
Correct |
255 ms |
4208 KB |
Output is correct |
74 |
Correct |
60 ms |
4216 KB |
Output is correct |
75 |
Correct |
62 ms |
4180 KB |
Output is correct |
76 |
Correct |
61 ms |
4212 KB |
Output is correct |
77 |
Correct |
62 ms |
4268 KB |
Output is correct |
78 |
Correct |
63 ms |
4160 KB |
Output is correct |