#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
void Hollwo_Pelw();
signed main(){
#ifndef hollwo_pelw_local
if (fopen("hollwo_pelw.inp", "r"))
assert(freopen("hollwo_pelw.inp", "r", stdin)), assert(freopen("hollwo_pelw.out", "w", stdout));
#else
using namespace chrono;
auto start = steady_clock::now();
#endif
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = steady_clock::now();
cout << "\nExcution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
const int N = 505, mod = 1e9 + 7;
int n, m, a[N], b[N], cnt[N * 2], dp[N * 2][N], inv[N];
vector<int> v, f;
void Hollwo_Pelw(){
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i] >> b[i], b[i] ++;
inv[1] = 1;
for (int i = 2; i <= n; i++)
inv[i] = mod - 1ll * (mod / i) * inv[mod % i] % mod;
for (int i = 1; i <= n; i++)
v.push_back(a[i]), v.push_back(b[i]);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
f.resize(m = v.size() - 1);
for (int i = 1; i < (int) v.size(); i++)
f[i - 1] = v[i] - v[i - 1];
for (int i = 0; i < m; i++)
cout << f[i] << " \n"[i == m - 1];
for (int i = 1; i <= n; i++) {
int l = lower_bound(v.begin(), v.end(), a[i]) - v.begin(), r = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
int cur = 1;
for (int j = 0; j < l; j++) {
for (int k = cnt[j]; k; k--)
if ((cur += dp[j][k]) >= mod)
cur -= mod;
}
for (int j = l; j < r; j++) {
int nxt = cur;
for (int k = cnt[j]; k; k--) {
if ((nxt += dp[j][k]) >= mod)
nxt -= mod;
dp[j][k + 1] += 1ll * dp[j][k] * (f[j] - k) % mod * inv[k + 1] % mod;
if (dp[j][k + 1] >= mod) dp[j][k + 1] -= mod;
}
++ cnt[j];
dp[j][1] += 1ll * cur * f[j] % mod;
if (dp[j][1] >= mod) dp[j][1] -= mod;
swap(nxt, cur);
}
// cout << "solve " << i << '\n';
// for (int j = 0; j < m; j++) if (cnt[j]) {
// cout << "j = " << j << " : ";
// for (int k = 1; k <= cnt[j]; k++)
// cout << dp[j][k] << " \n"[k == cnt[j]];
// }
}
int res = 0;
for (int j = 0; j < m; j++)
for (int k = 1; k <= cnt[j]; k++)
if ((res += dp[j][k]) >= mod)
res -= mod;
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |