# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
645054 | 2022-09-26T04:24:33 Z | ghostwriter | Boat (APIO16_boat) | C++14 | 1545 ms | 10196 KB |
#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 = 502; const int Nx2 = 1002; int n, m, inv[N], 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 (i == 1) { 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 && a1[i].nd <= r) { if (l < a1[i].st) seg1.pb({l, a1[i].st - 1}); seg1.pb(a1[i]); if (r > a1[i].nd) seg1.pb({a1[i].nd + 1, r}); } else 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, n) inv[i] = fpow(i, M - 2, M); 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 * inv[j] % 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) 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 5 3 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 641 ms | 5260 KB | Output is correct |
2 | Correct | 663 ms | 5260 KB | Output is correct |
3 | Correct | 717 ms | 5260 KB | Output is correct |
4 | Correct | 613 ms | 5260 KB | Output is correct |
5 | Correct | 631 ms | 5204 KB | Output is correct |
6 | Correct | 637 ms | 5272 KB | Output is correct |
7 | Correct | 655 ms | 5256 KB | Output is correct |
8 | Correct | 704 ms | 5204 KB | Output is correct |
9 | Correct | 640 ms | 5260 KB | Output is correct |
10 | Correct | 812 ms | 5256 KB | Output is correct |
11 | Correct | 678 ms | 5260 KB | Output is correct |
12 | Correct | 764 ms | 5256 KB | Output is correct |
13 | Correct | 650 ms | 5256 KB | Output is correct |
14 | Correct | 618 ms | 5260 KB | Output is correct |
15 | Correct | 606 ms | 5256 KB | Output is correct |
16 | Correct | 107 ms | 1212 KB | Output is correct |
17 | Correct | 114 ms | 1280 KB | Output is correct |
18 | Correct | 113 ms | 1240 KB | Output is correct |
19 | Correct | 117 ms | 1284 KB | Output is correct |
20 | Correct | 114 ms | 1256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 641 ms | 5260 KB | Output is correct |
2 | Correct | 663 ms | 5260 KB | Output is correct |
3 | Correct | 717 ms | 5260 KB | Output is correct |
4 | Correct | 613 ms | 5260 KB | Output is correct |
5 | Correct | 631 ms | 5204 KB | Output is correct |
6 | Correct | 637 ms | 5272 KB | Output is correct |
7 | Correct | 655 ms | 5256 KB | Output is correct |
8 | Correct | 704 ms | 5204 KB | Output is correct |
9 | Correct | 640 ms | 5260 KB | Output is correct |
10 | Correct | 812 ms | 5256 KB | Output is correct |
11 | Correct | 678 ms | 5260 KB | Output is correct |
12 | Correct | 764 ms | 5256 KB | Output is correct |
13 | Correct | 650 ms | 5256 KB | Output is correct |
14 | Correct | 618 ms | 5260 KB | Output is correct |
15 | Correct | 606 ms | 5256 KB | Output is correct |
16 | Correct | 107 ms | 1212 KB | Output is correct |
17 | Correct | 114 ms | 1280 KB | Output is correct |
18 | Correct | 113 ms | 1240 KB | Output is correct |
19 | Correct | 117 ms | 1284 KB | Output is correct |
20 | Correct | 114 ms | 1256 KB | Output is correct |
21 | Correct | 1316 ms | 9304 KB | Output is correct |
22 | Correct | 1398 ms | 9428 KB | Output is correct |
23 | Correct | 1289 ms | 9252 KB | Output is correct |
24 | Correct | 1292 ms | 9188 KB | Output is correct |
25 | Correct | 1299 ms | 9124 KB | Output is correct |
26 | Correct | 1338 ms | 8992 KB | Output is correct |
27 | Correct | 1341 ms | 9124 KB | Output is correct |
28 | Correct | 1315 ms | 9100 KB | Output is correct |
29 | Correct | 1300 ms | 8916 KB | Output is correct |
30 | Correct | 1305 ms | 10128 KB | Output is correct |
31 | Correct | 1328 ms | 10148 KB | Output is correct |
32 | Correct | 1340 ms | 10128 KB | Output is correct |
33 | Correct | 1320 ms | 10156 KB | Output is correct |
34 | Correct | 1294 ms | 10124 KB | Output is correct |
35 | Correct | 1346 ms | 10136 KB | Output is correct |
36 | Correct | 1298 ms | 10140 KB | Output is correct |
37 | Correct | 1334 ms | 10144 KB | Output is correct |
38 | Correct | 1302 ms | 10136 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 2260 KB | Output is correct |
2 | Correct | 14 ms | 2260 KB | Output is correct |
3 | Correct | 13 ms | 2260 KB | Output is correct |
4 | Correct | 13 ms | 2316 KB | Output is correct |
5 | Correct | 14 ms | 2316 KB | Output is correct |
6 | Correct | 14 ms | 2316 KB | Output is correct |
7 | Correct | 16 ms | 2312 KB | Output is correct |
8 | Correct | 14 ms | 2316 KB | Output is correct |
9 | Correct | 14 ms | 2320 KB | Output is correct |
10 | Correct | 14 ms | 2260 KB | Output is correct |
11 | Correct | 13 ms | 2316 KB | Output is correct |
12 | Correct | 13 ms | 2320 KB | Output is correct |
13 | Correct | 13 ms | 2260 KB | Output is correct |
14 | Correct | 13 ms | 2316 KB | Output is correct |
15 | Correct | 15 ms | 2260 KB | Output is correct |
16 | Correct | 7 ms | 1480 KB | Output is correct |
17 | Correct | 7 ms | 1364 KB | Output is correct |
18 | Correct | 7 ms | 1364 KB | Output is correct |
19 | Correct | 8 ms | 1364 KB | Output is correct |
20 | Correct | 8 ms | 1364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 641 ms | 5260 KB | Output is correct |
2 | Correct | 663 ms | 5260 KB | Output is correct |
3 | Correct | 717 ms | 5260 KB | Output is correct |
4 | Correct | 613 ms | 5260 KB | Output is correct |
5 | Correct | 631 ms | 5204 KB | Output is correct |
6 | Correct | 637 ms | 5272 KB | Output is correct |
7 | Correct | 655 ms | 5256 KB | Output is correct |
8 | Correct | 704 ms | 5204 KB | Output is correct |
9 | Correct | 640 ms | 5260 KB | Output is correct |
10 | Correct | 812 ms | 5256 KB | Output is correct |
11 | Correct | 678 ms | 5260 KB | Output is correct |
12 | Correct | 764 ms | 5256 KB | Output is correct |
13 | Correct | 650 ms | 5256 KB | Output is correct |
14 | Correct | 618 ms | 5260 KB | Output is correct |
15 | Correct | 606 ms | 5256 KB | Output is correct |
16 | Correct | 107 ms | 1212 KB | Output is correct |
17 | Correct | 114 ms | 1280 KB | Output is correct |
18 | Correct | 113 ms | 1240 KB | Output is correct |
19 | Correct | 117 ms | 1284 KB | Output is correct |
20 | Correct | 114 ms | 1256 KB | Output is correct |
21 | Correct | 1316 ms | 9304 KB | Output is correct |
22 | Correct | 1398 ms | 9428 KB | Output is correct |
23 | Correct | 1289 ms | 9252 KB | Output is correct |
24 | Correct | 1292 ms | 9188 KB | Output is correct |
25 | Correct | 1299 ms | 9124 KB | Output is correct |
26 | Correct | 1338 ms | 8992 KB | Output is correct |
27 | Correct | 1341 ms | 9124 KB | Output is correct |
28 | Correct | 1315 ms | 9100 KB | Output is correct |
29 | Correct | 1300 ms | 8916 KB | Output is correct |
30 | Correct | 1305 ms | 10128 KB | Output is correct |
31 | Correct | 1328 ms | 10148 KB | Output is correct |
32 | Correct | 1340 ms | 10128 KB | Output is correct |
33 | Correct | 1320 ms | 10156 KB | Output is correct |
34 | Correct | 1294 ms | 10124 KB | Output is correct |
35 | Correct | 1346 ms | 10136 KB | Output is correct |
36 | Correct | 1298 ms | 10140 KB | Output is correct |
37 | Correct | 1334 ms | 10144 KB | Output is correct |
38 | Correct | 1302 ms | 10136 KB | Output is correct |
39 | Correct | 13 ms | 2260 KB | Output is correct |
40 | Correct | 14 ms | 2260 KB | Output is correct |
41 | Correct | 13 ms | 2260 KB | Output is correct |
42 | Correct | 13 ms | 2316 KB | Output is correct |
43 | Correct | 14 ms | 2316 KB | Output is correct |
44 | Correct | 14 ms | 2316 KB | Output is correct |
45 | Correct | 16 ms | 2312 KB | Output is correct |
46 | Correct | 14 ms | 2316 KB | Output is correct |
47 | Correct | 14 ms | 2320 KB | Output is correct |
48 | Correct | 14 ms | 2260 KB | Output is correct |
49 | Correct | 13 ms | 2316 KB | Output is correct |
50 | Correct | 13 ms | 2320 KB | Output is correct |
51 | Correct | 13 ms | 2260 KB | Output is correct |
52 | Correct | 13 ms | 2316 KB | Output is correct |
53 | Correct | 15 ms | 2260 KB | Output is correct |
54 | Correct | 7 ms | 1480 KB | Output is correct |
55 | Correct | 7 ms | 1364 KB | Output is correct |
56 | Correct | 7 ms | 1364 KB | Output is correct |
57 | Correct | 8 ms | 1364 KB | Output is correct |
58 | Correct | 8 ms | 1364 KB | Output is correct |
59 | Correct | 1483 ms | 10196 KB | Output is correct |
60 | Correct | 1532 ms | 10196 KB | Output is correct |
61 | Correct | 1460 ms | 10188 KB | Output is correct |
62 | Correct | 1478 ms | 10196 KB | Output is correct |
63 | Correct | 1455 ms | 10196 KB | Output is correct |
64 | Correct | 1526 ms | 10120 KB | Output is correct |
65 | Correct | 1527 ms | 10176 KB | Output is correct |
66 | Correct | 1529 ms | 10196 KB | Output is correct |
67 | Correct | 1520 ms | 10196 KB | Output is correct |
68 | Correct | 1545 ms | 10184 KB | Output is correct |
69 | Correct | 1498 ms | 10188 KB | Output is correct |
70 | Correct | 1487 ms | 10196 KB | Output is correct |
71 | Correct | 1484 ms | 10188 KB | Output is correct |
72 | Correct | 1491 ms | 10180 KB | Output is correct |
73 | Correct | 1478 ms | 10196 KB | Output is correct |
74 | Correct | 247 ms | 2124 KB | Output is correct |
75 | Correct | 256 ms | 2172 KB | Output is correct |
76 | Correct | 249 ms | 2148 KB | Output is correct |
77 | Correct | 258 ms | 2156 KB | Output is correct |
78 | Correct | 243 ms | 2132 KB | Output is correct |