// https://oj.uz/problem/view/APIO16_boat
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0);
#define FASTIOF ios_base::sync_with_stdio(false); fin.tie(0);
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); }
const int MOD = 1e9 + 7;
const int MX = 510;
const ll INF = 1e18;
struct mint {
int v; explicit operator int() const { return v; }
mint() { v = 0; } mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD); if (v < 0) v += MOD; }
friend bool operator==(const mint& a, const mint& b) { return a.v == b.v; }
friend bool operator!=(const mint& a, const mint& b) { return !(a == b); }
friend bool operator<(const mint& a, const mint& b) { return a.v < b.v; }
mint& operator+=(const mint& m) { if ((v += m.v) >= MOD) v -= MOD; return *this; }
mint& operator-=(const mint& m) { if ((v -= m.v) < 0) v += MOD; return *this; }
mint& operator*=(const mint& m) { v = int((ll) v * m.v % MOD); return *this; }
mint& operator/=(const mint& m) { return (*this) *= inv(m); }
friend mint pow(mint a, long long p) {
mint ans = 1; for ( ; p; p /= 2, a *= a) if (p & 1) ans *= a; return ans;
}
friend mint inv(const mint& a) { return pow(a, MOD - 2); }
mint operator-() const { return mint(-v); }
mint& operator++() { return *this += 1; }
mint& operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint& b) { return a += b; }
friend mint operator-(mint a, const mint& b) { return a -= b; }
friend mint operator*(mint a, const mint& b) { return a *= b; }
friend mint operator/(mint a, const mint& b) { return a /= b; }
};
int N, M = 0, A[MX], B[MX]; vi al; mint DP[MX][2 * MX], in[MX];
int main() {
FASTIO;
cin >> N;
FOR(i, 1, N + 1) {
cin >> A[i] >> B[i];
B[i]++;
al.pb(A[i]);
al.pb(B[i]);
in[i] = inv((mint) i);
}
remDup(al);
FOR(i, 1, N + 1) {
A[i] = ub(all(al), A[i]) - al.bg();
B[i] = ub(all(al), B[i]) - al.bg();
ckmax(M, A[i]);
ckmax(M, B[i]);
}
DP[0][1] = 1;
FOR(i, 1, N + 1) {
FOR(j, 1, 2 * MX) {
DP[i][j] = DP[i - 1][j];
DP[i - 1][j] += DP[i - 1][j - 1];
}
FOR(j, A[i] + 1, B[i] + 1) {
int curL = al[j - 2];
int curR = al[j - 1] - 1;
int cntContained = 0;
mint curChoose = 1;
int val = curR - curL + 1;
R0F(k, i) {
int newL = al[A[k + 1] - 1];
int newR = al[B[k + 1] - 1] - 1;
if (!(newL <= curL && curR <= newR)) {
continue;
}
cntContained++;
if (cntContained > val) {
break;
}
// cout << val - cntContained + 1 << "\n";
curChoose *= (val - cntContained + 1);
curChoose *= in[cntContained];
// cout << int(curChoose) << "\n";
DP[i][j] += DP[k][j - 1] * curChoose;
}
}
}
mint ans = 0;
FOR(i, 2, M + 1) {
ans += DP[N][i];
}
cout << int(ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2380 KB |
Output is correct |
2 |
Correct |
4 ms |
2380 KB |
Output is correct |
3 |
Correct |
4 ms |
2380 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
4 ms |
2380 KB |
Output is correct |
6 |
Correct |
3 ms |
2364 KB |
Output is correct |
7 |
Correct |
3 ms |
2252 KB |
Output is correct |
8 |
Correct |
3 ms |
2380 KB |
Output is correct |
9 |
Correct |
3 ms |
2252 KB |
Output is correct |
10 |
Correct |
3 ms |
2328 KB |
Output is correct |
11 |
Correct |
3 ms |
2252 KB |
Output is correct |
12 |
Correct |
3 ms |
2252 KB |
Output is correct |
13 |
Correct |
3 ms |
2252 KB |
Output is correct |
14 |
Correct |
3 ms |
2252 KB |
Output is correct |
15 |
Correct |
3 ms |
2252 KB |
Output is correct |
16 |
Correct |
3 ms |
2380 KB |
Output is correct |
17 |
Correct |
3 ms |
2252 KB |
Output is correct |
18 |
Correct |
3 ms |
2252 KB |
Output is correct |
19 |
Correct |
3 ms |
2252 KB |
Output is correct |
20 |
Correct |
3 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2380 KB |
Output is correct |
2 |
Correct |
4 ms |
2380 KB |
Output is correct |
3 |
Correct |
4 ms |
2380 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
4 ms |
2380 KB |
Output is correct |
6 |
Correct |
3 ms |
2364 KB |
Output is correct |
7 |
Correct |
3 ms |
2252 KB |
Output is correct |
8 |
Correct |
3 ms |
2380 KB |
Output is correct |
9 |
Correct |
3 ms |
2252 KB |
Output is correct |
10 |
Correct |
3 ms |
2328 KB |
Output is correct |
11 |
Correct |
3 ms |
2252 KB |
Output is correct |
12 |
Correct |
3 ms |
2252 KB |
Output is correct |
13 |
Correct |
3 ms |
2252 KB |
Output is correct |
14 |
Correct |
3 ms |
2252 KB |
Output is correct |
15 |
Correct |
3 ms |
2252 KB |
Output is correct |
16 |
Correct |
3 ms |
2380 KB |
Output is correct |
17 |
Correct |
3 ms |
2252 KB |
Output is correct |
18 |
Correct |
3 ms |
2252 KB |
Output is correct |
19 |
Correct |
3 ms |
2252 KB |
Output is correct |
20 |
Correct |
3 ms |
2252 KB |
Output is correct |
21 |
Incorrect |
23 ms |
2360 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2380 KB |
Output is correct |
2 |
Correct |
4 ms |
2380 KB |
Output is correct |
3 |
Correct |
4 ms |
2380 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
4 ms |
2380 KB |
Output is correct |
6 |
Correct |
3 ms |
2364 KB |
Output is correct |
7 |
Correct |
3 ms |
2252 KB |
Output is correct |
8 |
Correct |
3 ms |
2380 KB |
Output is correct |
9 |
Correct |
3 ms |
2252 KB |
Output is correct |
10 |
Correct |
3 ms |
2328 KB |
Output is correct |
11 |
Correct |
3 ms |
2252 KB |
Output is correct |
12 |
Correct |
3 ms |
2252 KB |
Output is correct |
13 |
Correct |
3 ms |
2252 KB |
Output is correct |
14 |
Correct |
3 ms |
2252 KB |
Output is correct |
15 |
Correct |
3 ms |
2252 KB |
Output is correct |
16 |
Correct |
3 ms |
2380 KB |
Output is correct |
17 |
Correct |
3 ms |
2252 KB |
Output is correct |
18 |
Correct |
3 ms |
2252 KB |
Output is correct |
19 |
Correct |
3 ms |
2252 KB |
Output is correct |
20 |
Correct |
3 ms |
2252 KB |
Output is correct |
21 |
Incorrect |
23 ms |
2360 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |