# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1118532 | lmToT27 | Boat (APIO16_boat) | C++17 | 394 ms | 8344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(dataStructure) dataStructure.begin(),dataStructure.end()
using namespace std;
typedef long long ll;
const int MAX = 5e2 + 3;
const ll MOD[] = {1000000007, 998244353};
const ll mod = 1e9 + 7;
int n, l[MAX], r[MAX];
ll dp[MAX][2 * MAX], C[MAX][2 * MAX];
template <typename dataType>
inline void compress(vector <dataType> &x) {
sort(all(x));
x.erase(unique(all(x)), x.end());
}
ll pw(ll a, ll b) {
ll res = 1;
for (; b > 0; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
void Solve() {
vector <int> val;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> l[i] >> r[i];
l[i]--;
val.push_back(l[i]);
val.push_back(r[i]);
}
compress(val);
for (int i = 1; i < (int)val.size(); i++) {
int sz = val[i] - val[i - 1];
C[0][i] = sz;
for (int j = 1; j <= n; j++) {
C[j][i] = C[j - 1][i] * (sz + j - 1) % mod * pw(j, mod - 2) % mod;
}
dp[0][i] = 1;
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = 1;
for (int j = 1; j < (int)val.size(); j++) {
dp[i][j] = dp[i][j - 1];
int cnt = 0;
for (int k = i; k >= 1; k--) {
if (l[k] < val[j] && val[j] <= r[k]) {
cnt++;
dp[i][j] += dp[k - 1][j - 1] * C[cnt][j] % mod;
dp[i][j] %= mod;
}
}
}
}
cout << dp[n][(int)val.size() - 1] - 1;
}
int32_t main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0); std::cout.tie(0);
#define TASK ""
if (fopen(TASK".INP", "r")) {
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
if (fopen("TASK.INP", "r")) {
freopen("TASK.INP", "r", stdin);
freopen("TASK.OUT", "w", stdout);
}
/* int TEST = 1; cin >> TEST; while (TEST--) */ Solve();
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |