Submission #645028

#TimeUsernameProblemLanguageResultExecution timeMemory
645028ghostwriterBoat (APIO16_boat)C++14
9 / 100
1098 ms8300 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define bg begin #define ed end #define all(x) (x).bg(), (x).ed() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- DIT ME CHUYEN BAO LOC ---------------------------------------------------------------- */ const int M = 1e9 + 7; const int N = 505; const int Nx2 = 1005; int n, m, d[Nx2][N][2], d1[Nx2][N][2], d2[Nx2][N]; pi a[N], a1[N]; vpi seg; int fpow(int a, int b, int M) { if (b == 0) return 1; int tmp = fpow(a, b >> 1, M); if (b & 1) return 1LL * tmp * tmp % M * a % M; return 1LL * tmp * tmp % M; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n; FOR(i, 1, n) { cin >> a[i].st >> a[i].nd; a1[i] = a[i]; } sort(a1 + 1, a1 + 1 + n); FOR(i, 1, n) { if (seg.empty()) { seg.pb(a1[i]); continue; } if (a1[i].st > seg.bk().nd) { seg.pb(a1[i]); continue; } vpi seg1; EACH(j, seg) { int l = j.st, r = j.nd; if (l < a1[i].st && r >= a1[i].st) { seg1.pb({l, a1[i].st - 1}); seg1.pb({a1[i].st, r}); } else if (l <= a1[i].nd && r > a1[i].nd) { seg1.pb({l, a1[i].nd}); seg1.pb({a1[i].nd + 1, r}); } else seg1.pb({l, r}); } if (a1[i].nd > seg1.bk().nd) seg1.pb({seg1.bk().nd + 1, a1[i].nd}); swap(seg, seg1); } reverse(all(seg)); seg.pb({-1, -1}); reverse(all(seg)); m = sz(seg) - 1; FOR(i, 1, m) { d2[i][0] = 1; int cnt = min(n, seg[i].nd - seg[i].st + 1); FOR(j, 1, cnt) d2[i][j] = 1LL * d2[i][j - 1] * (seg[i].nd - seg[i].st + 2 - j) % M * fpow(j, M - 2, M) % M; } FOR(i, 1, m) FOR(j, 0, n) FOR(z, 0, 1) d1[i][j][z] = d2[i][j]; FOR(i, 1, n) { FOR(j, 1, m) FOR(z, 0, n - i) FOR(stat, 0, 1) { int &rs = d[j][z][stat]; rs = 0; if (stat) rs = (rs + d1[j][z][1]) % M; if (a[i].st <= seg[j].st && seg[j].nd <= a[i].nd && z < seg[j].nd - seg[j].st + 1) rs = (rs + d1[j][z + 1][1]) % M; if (j > 1) rs = (rs + 1LL * d2[j][z] * d[j - 1][0][0] % M) % M; } FOR(j, 1, m) FOR(z, 0, n - i) FOR(stat, 0, 1) d1[j][z][stat] = d[j][z][stat]; } cout << (d[m][0][1] - 1 + M) % M; return 0; } /* 2 1 2 2 3 ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:66:5: note: in expansion of macro 'FOR'
   66 |     FOR(i, 1, n) {
      |     ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:71:5: note: in expansion of macro 'FOR'
   71 |     FOR(i, 1, n) {
      |     ^~~
boat.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
boat.cpp:81:9: note: in expansion of macro 'EACH'
   81 |         EACH(j, seg) {
      |         ^~~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:100:5: note: in expansion of macro 'FOR'
  100 |     FOR(i, 1, m) {
      |     ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:103:9: note: in expansion of macro 'FOR'
  103 |         FOR(j, 1, cnt) d2[i][j] = 1LL * d2[i][j - 1] * (seg[i].nd - seg[i].st + 2 - j) % M * fpow(j, M - 2, M) % M;
      |         ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:105:5: note: in expansion of macro 'FOR'
  105 |     FOR(i, 1, m)
      |     ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:106:5: note: in expansion of macro 'FOR'
  106 |     FOR(j, 0, n)
      |     ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:107:5: note: in expansion of macro 'FOR'
  107 |     FOR(z, 0, 1)
      |     ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:109:5: note: in expansion of macro 'FOR'
  109 |     FOR(i, 1, n) {
      |     ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:110:9: note: in expansion of macro 'FOR'
  110 |         FOR(j, 1, m)
      |         ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:111:9: note: in expansion of macro 'FOR'
  111 |         FOR(z, 0, n - i)
      |         ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'stat' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:112:9: note: in expansion of macro 'FOR'
  112 |         FOR(stat, 0, 1) {
      |         ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:119:9: note: in expansion of macro 'FOR'
  119 |         FOR(j, 1, m)
      |         ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:120:9: note: in expansion of macro 'FOR'
  120 |         FOR(z, 0, n - i)
      |         ^~~
boat.cpp:30:31: warning: unnecessary parentheses in declaration of 'stat' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
boat.cpp:121:9: note: in expansion of macro 'FOR'
  121 |         FOR(stat, 0, 1)
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...