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 <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
inline int mul(int x, int y) { return (1LL*x*y)%MOD; }
int modpow(int x, int k) {
int a = 1;
while (k) {
if (k&1) a = mul(a, x);
x = mul(x, x);
k >>= 1;
}
return a;
}
int N;
int A[500], B[500];
int inv[501];
int dp[2][1000][501];
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N;
rep(k, N+1) inv[k] = modpow(k, MOD-2);
vector<int> ys;
rep(i, N) cin >> A[i] >> B[i], ys.pb(A[i]), ys.pb(B[i]+1);
sort(all(ys)); uniq(ys);
rep(i, N) A[i] = index(ys, A[i]), B[i] = index(ys, B[i]+1)-1;
dp[0][0][0] = 1;
rep(i, N) {
rep(j, ys.size()-1) rep(k, i+2) dp[1][j][k] = dp[0][j][k];
for (int j=A[i]; j<=B[i]; j++) rep(k, i+1) add(dp[1][j][k+1], mul(dp[0][j][k], mul(ys[j+1]-ys[j]-k, inv[k+1])));
int s = 0;
rep(t, B[i]+1) {
if (t >= A[i]) add(dp[1][t][1], mul(ys[t+1]-ys[t], s));
rep(k, i+1) add(s, dp[0][t][k]);
}
swap(dp[0], dp[1]);
}
int s = MOD-1;
rep(j, ys.size()-1) rep(k, N+1) add(s, dp[0][j][k]);
cout << s << "\n";
return 0;
}
Compilation message (stderr)
boat.cpp: In function 'int main()':
boat.cpp:17:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
boat.cpp:54:5: note: in expansion of macro 'rep'
rep(j, ys.size()-1) rep(k, i+2) dp[1][j][k] = dp[0][j][k];
^~~
boat.cpp:17:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
boat.cpp:64:3: note: in expansion of macro 'rep'
rep(j, ys.size()-1) rep(k, N+1) add(s, dp[0][j][k]);
^~~
# | 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... |