# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
558433 |
2022-05-07T10:10:19 Z |
hoanghq2004 |
Boat (APIO16_boat) |
C++14 |
|
1612 ms |
4424 KB |
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 510;
const int mod = 1e9 + 7;
int n, f[N * 2][N], g[N * 2][N], C[N][N];
int L[N], R[N], cur[N], inv[N];
void add(int& a, int b) {
a += b;
if (a >= mod) a -= mod;
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n;
vector <int> dta = {0};
for (int i = 1; i <= n; ++i) {
cin >> L[i] >> R[i];
--L[i];
dta.push_back(L[i]), dta.push_back(R[i]);
}
sort(dta.begin(), dta.end());
dta.erase(unique(dta.begin(), dta.end()), dta.end());
int m = dta.size();
C[0][0] = 1;
for (int i = 1; i < N; ++i) {
C[i][0] = 1;
for (int j = 1; j <= i; ++j)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
auto power = [&](int a, int n) {
int ans = 1;
for (; n; n >>= 1, a = 1LL * a * a % mod)
if (n & 1) ans = 1LL * ans * a % mod;
return ans;
};
inv[0] = 1;
for (int i = 1, fact = 1; i <= n; ++i, fact = 1LL * fact * i % mod) {
inv[i] = power(fact, mod - 2);
}
auto coef = [&](int n, int k) {
if (k > n - k) k = n - k;
int ans = inv[k];
for (int i = n - k + 1; i <= n; ++i) ans = 1LL * ans * i % mod;
return ans;
};
for (int i = 0; i <= n; ++i) f[i][0] = 1;
for (int s = 1; s < m; ++s) {
int d = dta[s] - dta[s - 1];
for (int i = 0; i <= n; ++i) cur[i] = coef(d, i);
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= i; ++j) {
g[s][i] = 1LL * C[i][j] * cur[j] % mod;
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j < m; ++j) {
f[i][j] = f[i][j - 1];
int cnt = 0;
for (int k = i; k > 0; --k) {
cnt += (L[k] < dta[j] && dta[j] <= R[k]);
add(f[i][j], 1LL * f[k - 1][j - 1] * g[j][cnt] % mod);
}
}
add(ans, f[i][m - 1] - 1);
}
cout << ans;
// f[n][m - 1] - 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1612 ms |
4424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1612 ms |
4424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
1876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1612 ms |
4424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |