# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
45019 | 2018-04-10T15:28:32 Z | OneSubmissionMan | Boat (APIO16_boat) | C++11 | 870 ms | 5232 KB |
# include <bits/stdc++.h> # define x first # define y second # define mp make_pair // everything go according to my plan # define pb push_back # define sz(a) (int)(a.size()) # define vec vector // shimkenttin kyzdary, dzyn, dzyn, dzyn... # define y1 Y_U_NO_y1 # define left Y_U_NO_left # define right Y_U_NO_right using namespace std; typedef pair <int, int> pii; typedef long long ll; typedef long double ld; const int Mod = (int)1e9 + 7; const int MX = 1073741822; const ll MXLL = 4e18; const int Sz = 1110111; // a pinch of soul inline void Read_rap () { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline void randomizer3000 () { unsigned int seed; asm ("rdtsc" : "=A"(seed)); srand (seed); } void files (string problem) { if (fopen ((problem + ".in").c_str(),"r")) { freopen ((problem + ".in").c_str(),"r",stdin); freopen ((problem + ".out").c_str(),"w",stdout); } } void localInput(const char in[] = "s") { if (fopen (in, "r")) { freopen (in, "r", stdin); } else cerr << "Warning: Input file not found" << endl; } const int N = 500 + 1; int n; map <int, vec<int> > add; int dp[2*N][N], pref[2*N][N]; void Add (int &a, int b) { a += b; if (a >= Mod) a -= Mod; } int binpow (ll a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % Mod; b >>= 1; a = (a * a) % Mod; } return res; } int inv (int a) { return binpow (a, Mod-2); } void Count (int cnt[], int n, int seglen) { memset (cnt, 0, (n + 1) * 4); static int dv[N]; for (int i = 1; i <= n; i++) dv[i] = inv (i); for (int k = 2; k <= n; k++) { ll kp = 1; ll lenp = 1; for (int p = 2; p <= min (seglen, k); p++) { if (p > 2) { kp = (kp * (k - p + 1) % Mod) * dv[p - 2] % Mod; lenp = (lenp * (seglen - p + 1) % Mod) * dv[p] % Mod; } else kp = 1, lenp = seglen * 1ll * (seglen-1) / 2 % Mod; Add (cnt[k], kp * lenp % Mod); } } } int main() { # ifdef Local //localInput(); # endif Read_rap(); cin >> n; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; add[a].pb (i); add[b + 1].pb (i); } vec <int> len (1); vec <vec <int> > v(1); set <int> s; for (auto x : add) len.pb (x.x), v.pb (x.y); for (int i = 1; i < sz(len) - 1; i++) len[i] = len[i + 1] - len[i]; len.pop_back(); for (int i = 0; i <= n; i++) pref[0][i] = 1; for (int t = 1; t < sz(len); t++) { int seglen = len[t]; for (auto y : v[t]) { if (s.count (y)) s.erase (y); else s.insert (y); } static vec<int> id; id = vec<int> (s.begin(), s.end()); static int cnt[N]; Count (cnt, sz(id), seglen); /* for (int i = 1; i <= sz(id); i++) cout << cnt[i] << ' '; cout << endl; */ for (int i = 0; i < sz(id); i++) { if (seglen > 1) { for (int j = i + 1; j < sz(id); j++) Add (dp[t][id[j]], cnt[j - i + 1] * 1ll * pref[t - 1][id[i] - 1] % Mod); } Add (dp[t][id[i]], seglen * 1ll * pref[t - 1][id[i] - 1] % Mod); } for (int i = 1; i <= n; i++) Add (dp[t][i], dp[t - 1][i]); pref[t][0] = 1; for (int i = 1; i <= n; i++) pref[t][i] = (pref[t][i - 1] + dp[t][i]) % Mod; } int ans = pref[sz(len) - 1][n] - 1; if (ans < 0) ans += Mod; cout << ans; return 0; } // Coded by Z..
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 4472 KB | Output is correct |
2 | Correct | 10 ms | 4472 KB | Output is correct |
3 | Correct | 9 ms | 4512 KB | Output is correct |
4 | Correct | 9 ms | 4716 KB | Output is correct |
5 | Correct | 9 ms | 4716 KB | Output is correct |
6 | Correct | 10 ms | 4716 KB | Output is correct |
7 | Correct | 9 ms | 4716 KB | Output is correct |
8 | Correct | 9 ms | 4716 KB | Output is correct |
9 | Correct | 9 ms | 4792 KB | Output is correct |
10 | Correct | 9 ms | 4796 KB | Output is correct |
11 | Correct | 9 ms | 4796 KB | Output is correct |
12 | Correct | 9 ms | 4796 KB | Output is correct |
13 | Correct | 9 ms | 4796 KB | Output is correct |
14 | Correct | 9 ms | 4796 KB | Output is correct |
15 | Correct | 9 ms | 4796 KB | Output is correct |
16 | Correct | 3 ms | 4796 KB | Output is correct |
17 | Correct | 4 ms | 4796 KB | Output is correct |
18 | Correct | 3 ms | 4796 KB | Output is correct |
19 | Correct | 4 ms | 4796 KB | Output is correct |
20 | Correct | 3 ms | 4796 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 4472 KB | Output is correct |
2 | Correct | 10 ms | 4472 KB | Output is correct |
3 | Correct | 9 ms | 4512 KB | Output is correct |
4 | Correct | 9 ms | 4716 KB | Output is correct |
5 | Correct | 9 ms | 4716 KB | Output is correct |
6 | Correct | 10 ms | 4716 KB | Output is correct |
7 | Correct | 9 ms | 4716 KB | Output is correct |
8 | Correct | 9 ms | 4716 KB | Output is correct |
9 | Correct | 9 ms | 4792 KB | Output is correct |
10 | Correct | 9 ms | 4796 KB | Output is correct |
11 | Correct | 9 ms | 4796 KB | Output is correct |
12 | Correct | 9 ms | 4796 KB | Output is correct |
13 | Correct | 9 ms | 4796 KB | Output is correct |
14 | Correct | 9 ms | 4796 KB | Output is correct |
15 | Correct | 9 ms | 4796 KB | Output is correct |
16 | Correct | 3 ms | 4796 KB | Output is correct |
17 | Correct | 4 ms | 4796 KB | Output is correct |
18 | Correct | 3 ms | 4796 KB | Output is correct |
19 | Correct | 4 ms | 4796 KB | Output is correct |
20 | Correct | 3 ms | 4796 KB | Output is correct |
21 | Correct | 106 ms | 4796 KB | Output is correct |
22 | Correct | 101 ms | 4796 KB | Output is correct |
23 | Correct | 90 ms | 4796 KB | Output is correct |
24 | Correct | 102 ms | 4796 KB | Output is correct |
25 | Correct | 102 ms | 4796 KB | Output is correct |
26 | Correct | 179 ms | 4796 KB | Output is correct |
27 | Correct | 178 ms | 4796 KB | Output is correct |
28 | Correct | 178 ms | 4796 KB | Output is correct |
29 | Correct | 224 ms | 4796 KB | Output is correct |
30 | Correct | 11 ms | 4796 KB | Output is correct |
31 | Correct | 12 ms | 4808 KB | Output is correct |
32 | Correct | 9 ms | 4932 KB | Output is correct |
33 | Correct | 11 ms | 4932 KB | Output is correct |
34 | Correct | 9 ms | 4932 KB | Output is correct |
35 | Correct | 9 ms | 4932 KB | Output is correct |
36 | Correct | 9 ms | 4932 KB | Output is correct |
37 | Correct | 9 ms | 4932 KB | Output is correct |
38 | Correct | 10 ms | 4932 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4932 KB | Output is correct |
2 | Correct | 5 ms | 4932 KB | Output is correct |
3 | Correct | 6 ms | 4932 KB | Output is correct |
4 | Correct | 6 ms | 4932 KB | Output is correct |
5 | Correct | 7 ms | 4932 KB | Output is correct |
6 | Correct | 11 ms | 4932 KB | Output is correct |
7 | Correct | 11 ms | 4932 KB | Output is correct |
8 | Correct | 11 ms | 4932 KB | Output is correct |
9 | Correct | 11 ms | 4932 KB | Output is correct |
10 | Correct | 11 ms | 4932 KB | Output is correct |
11 | Correct | 7 ms | 4932 KB | Output is correct |
12 | Correct | 6 ms | 4932 KB | Output is correct |
13 | Correct | 6 ms | 4932 KB | Output is correct |
14 | Correct | 6 ms | 4932 KB | Output is correct |
15 | Correct | 7 ms | 4932 KB | Output is correct |
16 | Correct | 5 ms | 4932 KB | Output is correct |
17 | Correct | 4 ms | 4932 KB | Output is correct |
18 | Correct | 4 ms | 4932 KB | Output is correct |
19 | Correct | 4 ms | 4932 KB | Output is correct |
20 | Correct | 5 ms | 4932 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 4472 KB | Output is correct |
2 | Correct | 10 ms | 4472 KB | Output is correct |
3 | Correct | 9 ms | 4512 KB | Output is correct |
4 | Correct | 9 ms | 4716 KB | Output is correct |
5 | Correct | 9 ms | 4716 KB | Output is correct |
6 | Correct | 10 ms | 4716 KB | Output is correct |
7 | Correct | 9 ms | 4716 KB | Output is correct |
8 | Correct | 9 ms | 4716 KB | Output is correct |
9 | Correct | 9 ms | 4792 KB | Output is correct |
10 | Correct | 9 ms | 4796 KB | Output is correct |
11 | Correct | 9 ms | 4796 KB | Output is correct |
12 | Correct | 9 ms | 4796 KB | Output is correct |
13 | Correct | 9 ms | 4796 KB | Output is correct |
14 | Correct | 9 ms | 4796 KB | Output is correct |
15 | Correct | 9 ms | 4796 KB | Output is correct |
16 | Correct | 3 ms | 4796 KB | Output is correct |
17 | Correct | 4 ms | 4796 KB | Output is correct |
18 | Correct | 3 ms | 4796 KB | Output is correct |
19 | Correct | 4 ms | 4796 KB | Output is correct |
20 | Correct | 3 ms | 4796 KB | Output is correct |
21 | Correct | 106 ms | 4796 KB | Output is correct |
22 | Correct | 101 ms | 4796 KB | Output is correct |
23 | Correct | 90 ms | 4796 KB | Output is correct |
24 | Correct | 102 ms | 4796 KB | Output is correct |
25 | Correct | 102 ms | 4796 KB | Output is correct |
26 | Correct | 179 ms | 4796 KB | Output is correct |
27 | Correct | 178 ms | 4796 KB | Output is correct |
28 | Correct | 178 ms | 4796 KB | Output is correct |
29 | Correct | 224 ms | 4796 KB | Output is correct |
30 | Correct | 11 ms | 4796 KB | Output is correct |
31 | Correct | 12 ms | 4808 KB | Output is correct |
32 | Correct | 9 ms | 4932 KB | Output is correct |
33 | Correct | 11 ms | 4932 KB | Output is correct |
34 | Correct | 9 ms | 4932 KB | Output is correct |
35 | Correct | 9 ms | 4932 KB | Output is correct |
36 | Correct | 9 ms | 4932 KB | Output is correct |
37 | Correct | 9 ms | 4932 KB | Output is correct |
38 | Correct | 10 ms | 4932 KB | Output is correct |
39 | Correct | 6 ms | 4932 KB | Output is correct |
40 | Correct | 5 ms | 4932 KB | Output is correct |
41 | Correct | 6 ms | 4932 KB | Output is correct |
42 | Correct | 6 ms | 4932 KB | Output is correct |
43 | Correct | 7 ms | 4932 KB | Output is correct |
44 | Correct | 11 ms | 4932 KB | Output is correct |
45 | Correct | 11 ms | 4932 KB | Output is correct |
46 | Correct | 11 ms | 4932 KB | Output is correct |
47 | Correct | 11 ms | 4932 KB | Output is correct |
48 | Correct | 11 ms | 4932 KB | Output is correct |
49 | Correct | 7 ms | 4932 KB | Output is correct |
50 | Correct | 6 ms | 4932 KB | Output is correct |
51 | Correct | 6 ms | 4932 KB | Output is correct |
52 | Correct | 6 ms | 4932 KB | Output is correct |
53 | Correct | 7 ms | 4932 KB | Output is correct |
54 | Correct | 5 ms | 4932 KB | Output is correct |
55 | Correct | 4 ms | 4932 KB | Output is correct |
56 | Correct | 4 ms | 4932 KB | Output is correct |
57 | Correct | 4 ms | 4932 KB | Output is correct |
58 | Correct | 5 ms | 4932 KB | Output is correct |
59 | Correct | 375 ms | 4932 KB | Output is correct |
60 | Correct | 344 ms | 4932 KB | Output is correct |
61 | Correct | 322 ms | 4932 KB | Output is correct |
62 | Correct | 404 ms | 4984 KB | Output is correct |
63 | Correct | 357 ms | 5072 KB | Output is correct |
64 | Correct | 870 ms | 5224 KB | Output is correct |
65 | Correct | 851 ms | 5232 KB | Output is correct |
66 | Correct | 856 ms | 5232 KB | Output is correct |
67 | Correct | 868 ms | 5232 KB | Output is correct |
68 | Correct | 855 ms | 5232 KB | Output is correct |
69 | Correct | 319 ms | 5232 KB | Output is correct |
70 | Correct | 328 ms | 5232 KB | Output is correct |
71 | Correct | 332 ms | 5232 KB | Output is correct |
72 | Correct | 348 ms | 5232 KB | Output is correct |
73 | Correct | 352 ms | 5232 KB | Output is correct |
74 | Correct | 44 ms | 5232 KB | Output is correct |
75 | Correct | 43 ms | 5232 KB | Output is correct |
76 | Correct | 42 ms | 5232 KB | Output is correct |
77 | Correct | 49 ms | 5232 KB | Output is correct |
78 | Correct | 45 ms | 5232 KB | Output is correct |