# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143040 | HellAngel | Boat (APIO16_boat) | C++14 | 454 ms | 12468 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 int long long
using namespace std;
const int maxn = 1007;
const int somod = 1e9 + 7;
int n, m, a[maxn], b[maxn];
int precal[maxn][maxn], s[maxn][maxn], cnt[maxn];
vector<int> vt;
int BIT[maxn], ans[maxn], dp[maxn][maxn], total[maxn];
int Pow(int i, int j)
{
if(j == 0) return 1;
int mid = Pow(i, j / 2);
mid = mid * mid % somod;
if(j & 1) mid = mid * i % somod;
return mid;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
vt.push_back(a[i]);
vt.push_back(b[i] + 1);
}
sort(vt.begin(), vt.end());
vt.erase(unique(vt.begin(), vt.end()), vt.end());
int k = vt.size();
k--;
for(int i = 1; i <= k; i++)
{
precal[i][0] = 1;
int Dist = vt[i] - vt[i - 1];
precal[i][1] = Dist;
for(int j = 2; j <= n + 1; j++)
{
precal[i][j] = precal[i][j - 1] * (Dist + j - 1) % somod * Pow(j, somod - 2) % somod; ///figurate number
}
}
for(int i = 1; i <= n; i++)
{
int sum = 0;
for(int j = 1; j <= k; j++)
{
int sum = 0, dem = 1;
int gau = precal[j][dem];
if(a[i] <= vt[j - 1] && vt[j] - 1 <= b[i])
{
cnt[j]++;
for(int t = i - 1; t >= 1; t--)
{
sum = (sum + gau * s[t][j - 1]) % somod;
if(a[t] <= vt[j - 1] && vt[j] - 1 <= b[t]) gau = (gau + precal[j][++dem] - vt[j] + vt[j - 1] + somod) % somod;
}
sum = (sum + precal[j][cnt[j]]) % somod;
}
s[i][j] = (s[i][j - 1] + sum) % somod;
}
}
int ans = 0;
for(int i = 1; i <= n; i++) ans = (ans + s[i][k]) % somod;
cout << ans;
}
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... |