# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
801683 |
2023-08-02T07:12:57 Z |
peijar |
Boat (APIO16_boat) |
C++17 |
|
14 ms |
1236 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
bool first = true;
string res = "[";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "]";
return res;
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << to_string(H);
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
template <const int32_t MOD> struct ModInt {
int32_t x;
ModInt() : x(0) {}
ModInt(long long u) : x(u % MOD) {
if (x < 0)
x += MOD;
}
friend bool operator==(const ModInt &a, const ModInt &b) {
return a.x == b.x;
}
friend bool operator!=(const ModInt &a, const ModInt &b) {
return a.x != b.x;
}
friend bool operator<(const ModInt &a, const ModInt &b) { return a.x < b.x; }
friend bool operator>(const ModInt &a, const ModInt &b) { return a.x > b.x; }
friend bool operator<=(const ModInt &a, const ModInt &b) {
return a.x <= b.x;
}
friend bool operator>=(const ModInt &a, const ModInt &b) {
return a.x >= b.x;
}
static ModInt sign(long long k) {
return ((k & 1) ? ModInt(MOD - 1) : ModInt(1));
}
ModInt &operator+=(const ModInt &m) {
x += m.x;
if (x >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(const ModInt &m) {
x -= m.x;
if (x < 0LL)
x += MOD;
return *this;
}
ModInt &operator*=(const ModInt &m) {
x = (1LL * x * m.x) % MOD;
return *this;
}
friend ModInt operator-(const ModInt &a) {
ModInt res(a);
if (res.x)
res.x = MOD - res.x;
return res;
}
friend ModInt operator+(const ModInt &a, const ModInt &b) {
return ModInt(a) += ModInt(b);
}
friend ModInt operator-(const ModInt &a, const ModInt &b) {
return ModInt(a) -= ModInt(b);
}
friend ModInt operator*(const ModInt &a, const ModInt &b) {
return ModInt(a) *= ModInt(b);
}
static long long fp(long long u, long long k) {
long long res = 1LL;
while (k > 0LL) {
if (k & 1LL)
res = (res * u) % MOD;
u = (u * u) % MOD;
k /= 2LL;
}
return res;
}
static constexpr int mod() { return MOD; }
ModInt fastpow(long long k) { return ModInt(fp(x, k)); }
ModInt inv() {
assert(x);
return ModInt(fp(x, MOD - 2));
}
ModInt &operator/=(const ModInt &m) { return *this *= ModInt(m).inv(); }
friend ModInt operator/(const ModInt &a, const ModInt &b) {
return ModInt(a) *= ModInt(b).inv();
}
friend ostream &operator<<(ostream &out, const ModInt &a) {
return out << a.x;
}
friend istream &operator>>(istream &in, ModInt &a) { return in >> a.x; }
friend string to_string(ModInt u) { return to_string(u.x); }
};
const int MOD = 1e9 + 7;
using Mint = ModInt<MOD>;
const int MAXN = 1e5;
Mint fact[MAXN], invFact[MAXN];
void initFact() {
fact[0] = 1;
for (int i = 1; i < MAXN; ++i)
fact[i] = i * fact[i - 1];
invFact[MAXN - 1] = fact[MAXN - 1].inv();
for (int i = MAXN - 1; i; --i)
invFact[i - 1] = invFact[i] * i;
}
map<pair<int, int>, Mint> cache;
Mint binom(int n, int k) {
if (k < 0 or k > n)
return 0;
if (cache.count({n, k}))
return cache[{n, k}];
Mint ret = 1;
for (int i = n; i > n - k; --i)
ret *= i;
ret *= invFact[k];
return cache[{n, k}] = ret;
}
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
initFact();
int nbEcoles;
cin >> nbEcoles;
map<int, vector<int>> events;
for (int iEcole = 0; iEcole < nbEcoles; ++iEcole) {
int lo, up;
cin >> lo >> up;
events[lo].push_back(iEcole);
events[1 + up].push_back(iEcole);
}
vector<Mint> dp(nbEcoles);
set<int> on;
int prev = 0;
for (auto [timeStamp, toUpdate] : events) {
for (int x : toUpdate) {
if (on.count(x))
on.erase(x);
else
on.insert(x);
}
int lo = prev + 1, up = timeStamp;
vector<int> vec(on.begin(), on.end());
vector<Mint> nxtDp(on.size());
for (int fst = 0; fst < (int)on.size(); ++fst)
for (int lst = fst; lst < (int)on.size(); ++lst) {
int middle = max(0LL, fst - lst - 1);
for (int takeMiddle = 0; takeMiddle <= middle; ++takeMiddle) {
Mint choixEcoles = binom(middle, takeMiddle);
Mint choixCnt = binom(up - lo + 1, takeMiddle + 1 + (fst != lst));
Mint choixAvant =
1 + accumulate(dp.begin(), dp.begin() + vec[fst], Mint(0));
nxtDp[lst] += choixEcoles * choixCnt * choixAvant;
}
}
for (int i = 0; i < (int)on.size(); ++i)
dp[vec[i]] += nxtDp[i];
prev = up;
}
cout << accumulate(dp.begin(), dp.end(), Mint(0)) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |