# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
236368 |
2020-06-01T15:08:22 Z |
LordOfIran |
Boat (APIO16_boat) |
C++14 |
|
514 ms |
9172 KB |
// In The Name Of Allah
// Mohammad Hosseini
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2000, OO = 1e9 + 7, T = 20, M = 1e9 + 7, P = 6151, SQ = 800, lg = 20;
typedef pair <int, int> pii;
pii p[N];
int dp[N][N], inv[N];
vector <int> g[N];
int pw(int x, int y) {
if(y == 0)
return 1;
int cnt = pw(x, y / 2);
cnt = (cnt * cnt) % M;
if(y % 2)
cnt = (cnt * x) % M;
return cnt;
}
int32_t main() {
use_fast;
int n;
cin >> n;
vector <int> v = {0, OO};
for(int i = 1; i < N - 100; i++)
inv[i] = pw(i, M - 2);
for(int i = 1; i <= n; i++) {
cin >> p[i].ff >> p[i].ss;
p[i].ss++;
v.pb(p[i].ff);
v.pb(p[i].ss);
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for(int i = 1; i < (int)v.size(); i++)
dp[0][i] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j < (int)v.size(); j++) {
dp[i][j] = dp[i][j - 1];
if(!(p[i].ff <= v[j - 1] && v[j] <= p[i].ss))
continue;
int l = v[j] - v[j - 1], up = (l * (l - 1) / 2) % M, nxt = 1;
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * l) % M;
for(int k = (int)g[j].size() - 1; k >= 0; k--) {
dp[i][j] = (dp[i][j] + dp[g[j][k] - 1][j - 1] * up) % M;
up = (up * (l + nxt)) % M;
up = (up * inv[nxt + 2]) % M;
nxt++;
}
g[j].pb(i);
}
for(int j = 1; j < (int)v.size(); j++)
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % M;
}
cout << (dp[n][(int)v.size() - 1] - 1 + M) % M << endl;
return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ...
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6400 KB |
Output is correct |
2 |
Correct |
11 ms |
6400 KB |
Output is correct |
3 |
Correct |
10 ms |
6400 KB |
Output is correct |
4 |
Correct |
11 ms |
6400 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
10 ms |
6272 KB |
Output is correct |
7 |
Correct |
10 ms |
6400 KB |
Output is correct |
8 |
Correct |
10 ms |
6400 KB |
Output is correct |
9 |
Correct |
11 ms |
6400 KB |
Output is correct |
10 |
Correct |
11 ms |
6400 KB |
Output is correct |
11 |
Correct |
10 ms |
6400 KB |
Output is correct |
12 |
Correct |
11 ms |
6400 KB |
Output is correct |
13 |
Correct |
11 ms |
6400 KB |
Output is correct |
14 |
Correct |
11 ms |
6400 KB |
Output is correct |
15 |
Correct |
11 ms |
6400 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
7 ms |
3200 KB |
Output is correct |
18 |
Correct |
7 ms |
3200 KB |
Output is correct |
19 |
Correct |
7 ms |
3200 KB |
Output is correct |
20 |
Correct |
7 ms |
3200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6400 KB |
Output is correct |
2 |
Correct |
11 ms |
6400 KB |
Output is correct |
3 |
Correct |
10 ms |
6400 KB |
Output is correct |
4 |
Correct |
11 ms |
6400 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
10 ms |
6272 KB |
Output is correct |
7 |
Correct |
10 ms |
6400 KB |
Output is correct |
8 |
Correct |
10 ms |
6400 KB |
Output is correct |
9 |
Correct |
11 ms |
6400 KB |
Output is correct |
10 |
Correct |
11 ms |
6400 KB |
Output is correct |
11 |
Correct |
10 ms |
6400 KB |
Output is correct |
12 |
Correct |
11 ms |
6400 KB |
Output is correct |
13 |
Correct |
11 ms |
6400 KB |
Output is correct |
14 |
Correct |
11 ms |
6400 KB |
Output is correct |
15 |
Correct |
11 ms |
6400 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
7 ms |
3200 KB |
Output is correct |
18 |
Correct |
7 ms |
3200 KB |
Output is correct |
19 |
Correct |
7 ms |
3200 KB |
Output is correct |
20 |
Correct |
7 ms |
3200 KB |
Output is correct |
21 |
Correct |
208 ms |
7928 KB |
Output is correct |
22 |
Correct |
196 ms |
7928 KB |
Output is correct |
23 |
Correct |
177 ms |
7544 KB |
Output is correct |
24 |
Correct |
195 ms |
7672 KB |
Output is correct |
25 |
Correct |
214 ms |
7676 KB |
Output is correct |
26 |
Correct |
445 ms |
8184 KB |
Output is correct |
27 |
Correct |
454 ms |
8440 KB |
Output is correct |
28 |
Correct |
448 ms |
8312 KB |
Output is correct |
29 |
Correct |
440 ms |
8184 KB |
Output is correct |
30 |
Correct |
11 ms |
6400 KB |
Output is correct |
31 |
Correct |
11 ms |
6400 KB |
Output is correct |
32 |
Correct |
11 ms |
6400 KB |
Output is correct |
33 |
Correct |
11 ms |
6400 KB |
Output is correct |
34 |
Correct |
11 ms |
6400 KB |
Output is correct |
35 |
Correct |
10 ms |
6400 KB |
Output is correct |
36 |
Correct |
11 ms |
6400 KB |
Output is correct |
37 |
Correct |
10 ms |
6400 KB |
Output is correct |
38 |
Correct |
11 ms |
6400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1024 KB |
Output is correct |
2 |
Correct |
7 ms |
1024 KB |
Output is correct |
3 |
Correct |
7 ms |
1024 KB |
Output is correct |
4 |
Correct |
7 ms |
1024 KB |
Output is correct |
5 |
Correct |
7 ms |
1024 KB |
Output is correct |
6 |
Correct |
10 ms |
1024 KB |
Output is correct |
7 |
Correct |
10 ms |
1024 KB |
Output is correct |
8 |
Correct |
9 ms |
1024 KB |
Output is correct |
9 |
Correct |
9 ms |
1152 KB |
Output is correct |
10 |
Correct |
10 ms |
1024 KB |
Output is correct |
11 |
Correct |
8 ms |
1152 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
13 |
Correct |
7 ms |
1024 KB |
Output is correct |
14 |
Correct |
7 ms |
1024 KB |
Output is correct |
15 |
Correct |
7 ms |
1088 KB |
Output is correct |
16 |
Correct |
7 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
896 KB |
Output is correct |
18 |
Correct |
7 ms |
896 KB |
Output is correct |
19 |
Correct |
6 ms |
1024 KB |
Output is correct |
20 |
Correct |
7 ms |
960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6400 KB |
Output is correct |
2 |
Correct |
11 ms |
6400 KB |
Output is correct |
3 |
Correct |
10 ms |
6400 KB |
Output is correct |
4 |
Correct |
11 ms |
6400 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
10 ms |
6272 KB |
Output is correct |
7 |
Correct |
10 ms |
6400 KB |
Output is correct |
8 |
Correct |
10 ms |
6400 KB |
Output is correct |
9 |
Correct |
11 ms |
6400 KB |
Output is correct |
10 |
Correct |
11 ms |
6400 KB |
Output is correct |
11 |
Correct |
10 ms |
6400 KB |
Output is correct |
12 |
Correct |
11 ms |
6400 KB |
Output is correct |
13 |
Correct |
11 ms |
6400 KB |
Output is correct |
14 |
Correct |
11 ms |
6400 KB |
Output is correct |
15 |
Correct |
11 ms |
6400 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
7 ms |
3200 KB |
Output is correct |
18 |
Correct |
7 ms |
3200 KB |
Output is correct |
19 |
Correct |
7 ms |
3200 KB |
Output is correct |
20 |
Correct |
7 ms |
3200 KB |
Output is correct |
21 |
Correct |
208 ms |
7928 KB |
Output is correct |
22 |
Correct |
196 ms |
7928 KB |
Output is correct |
23 |
Correct |
177 ms |
7544 KB |
Output is correct |
24 |
Correct |
195 ms |
7672 KB |
Output is correct |
25 |
Correct |
214 ms |
7676 KB |
Output is correct |
26 |
Correct |
445 ms |
8184 KB |
Output is correct |
27 |
Correct |
454 ms |
8440 KB |
Output is correct |
28 |
Correct |
448 ms |
8312 KB |
Output is correct |
29 |
Correct |
440 ms |
8184 KB |
Output is correct |
30 |
Correct |
11 ms |
6400 KB |
Output is correct |
31 |
Correct |
11 ms |
6400 KB |
Output is correct |
32 |
Correct |
11 ms |
6400 KB |
Output is correct |
33 |
Correct |
11 ms |
6400 KB |
Output is correct |
34 |
Correct |
11 ms |
6400 KB |
Output is correct |
35 |
Correct |
10 ms |
6400 KB |
Output is correct |
36 |
Correct |
11 ms |
6400 KB |
Output is correct |
37 |
Correct |
10 ms |
6400 KB |
Output is correct |
38 |
Correct |
11 ms |
6400 KB |
Output is correct |
39 |
Correct |
7 ms |
1024 KB |
Output is correct |
40 |
Correct |
7 ms |
1024 KB |
Output is correct |
41 |
Correct |
7 ms |
1024 KB |
Output is correct |
42 |
Correct |
7 ms |
1024 KB |
Output is correct |
43 |
Correct |
7 ms |
1024 KB |
Output is correct |
44 |
Correct |
10 ms |
1024 KB |
Output is correct |
45 |
Correct |
10 ms |
1024 KB |
Output is correct |
46 |
Correct |
9 ms |
1024 KB |
Output is correct |
47 |
Correct |
9 ms |
1152 KB |
Output is correct |
48 |
Correct |
10 ms |
1024 KB |
Output is correct |
49 |
Correct |
8 ms |
1152 KB |
Output is correct |
50 |
Correct |
7 ms |
1024 KB |
Output is correct |
51 |
Correct |
7 ms |
1024 KB |
Output is correct |
52 |
Correct |
7 ms |
1024 KB |
Output is correct |
53 |
Correct |
7 ms |
1088 KB |
Output is correct |
54 |
Correct |
7 ms |
1024 KB |
Output is correct |
55 |
Correct |
7 ms |
896 KB |
Output is correct |
56 |
Correct |
7 ms |
896 KB |
Output is correct |
57 |
Correct |
6 ms |
1024 KB |
Output is correct |
58 |
Correct |
7 ms |
960 KB |
Output is correct |
59 |
Correct |
222 ms |
8184 KB |
Output is correct |
60 |
Correct |
198 ms |
8056 KB |
Output is correct |
61 |
Correct |
193 ms |
8056 KB |
Output is correct |
62 |
Correct |
229 ms |
8444 KB |
Output is correct |
63 |
Correct |
216 ms |
8184 KB |
Output is correct |
64 |
Correct |
509 ms |
9172 KB |
Output is correct |
65 |
Correct |
508 ms |
9108 KB |
Output is correct |
66 |
Correct |
509 ms |
9072 KB |
Output is correct |
67 |
Correct |
514 ms |
9044 KB |
Output is correct |
68 |
Correct |
509 ms |
8952 KB |
Output is correct |
69 |
Correct |
188 ms |
8184 KB |
Output is correct |
70 |
Correct |
194 ms |
8056 KB |
Output is correct |
71 |
Correct |
194 ms |
8032 KB |
Output is correct |
72 |
Correct |
206 ms |
8056 KB |
Output is correct |
73 |
Correct |
205 ms |
7928 KB |
Output is correct |
74 |
Correct |
49 ms |
3448 KB |
Output is correct |
75 |
Correct |
46 ms |
3448 KB |
Output is correct |
76 |
Correct |
48 ms |
3452 KB |
Output is correct |
77 |
Correct |
49 ms |
3448 KB |
Output is correct |
78 |
Correct |
50 ms |
3576 KB |
Output is correct |