// 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[2 * MX]; int val[2 * MX];
int main() {
FASTIO;
cin >> N;
FOR(i, 1, N + 1) {
cin >> A[i] >> B[i];
al.pb(A[i]);
al.pb(B[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]);
}
val[1] = al[0];
FOR(i, 2, M + 1) {
val[i] = al[i - 1] - al[i - 2];
}
DP[0] = 1;
FOR(i, 1, N + 1) {
mint nDP[2 * MX];
F0R(j, M + 1) {
nDP[j] = DP[j];
}
mint curPref[2 * MX];
curPref[0] = DP[0];
FOR(j, 1, M + 1) {
curPref[j] = curPref[j - 1] + DP[j];
}
FOR(j, A[i], B[i] + 1) {
nDP[j] += val[j] * curPref[j - 1];
}
F0R(j, M + 1) {
DP[j] = nDP[j];
}
}
mint ans = 0;
FOR(i, 1, M + 1) {
ans += DP[i];
}
cout << int(ans) << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |