# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
480664 |
2021-10-17T15:13:47 Z |
TAMREF |
Boat (APIO16_boat) |
C++17 |
|
1427 ms |
8352 KB |
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define pp push_back
#define ep emplace_back
#define all(v) (v).begin(),(v).end()
#define szz(v) ((int)(v).size())
#define bi_pc __builtin_popcount
#define bi_pcll __builtin_popcountll
#define bi_tz __builtin_ctz
#define bi_tzll __builtin_ctzll
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef TAMREF
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 42
#endif
using namespace std;
using ll = long long; using lf = long double;
using pii = pair<int,int>; using ppi = pair<int,pii>;
using pll = pair<ll,ll>; using pff = pair<lf,lf>;
using ti = tuple<int,int,int>;
using base = complex<double>;
const lf PI = 3.14159265358979323846264338L;
template <typename T>
inline T umax(T& u, T v){return u = max(u, v);}
template <typename T>
inline T umin(T& u, T v){return u = min(u, v);}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7;
ll inv[505] = {0, 1};
int n;
vector<int> cmp;
int a[505], b[505];
ll a_Ijk[2][1005][505]; // i' < i, j' = j, k' = k
ll b_ij[2][1005]; //i' < i, j' < j, k' arb
ll ans;
int main(){
fio;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
++b[i];
cmp.pp(a[i]); cmp.pp(b[i]);
}
for(int i = 2; i <= n; i++) {
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
debug("inv[%d] = %lld\n", i, inv[i]);
}
sort(all(cmp)); cmp.erase(unique(all(cmp)), cmp.end());
int d = szz(cmp);
for(int i = 1; i <= n; i++) {
a[i] = lb(all(cmp), a[i]) - cmp.begin() + 1;
b[i] = lb(all(cmp), b[i]) - cmp.begin() + 1;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j < d; j++) {
b_ij[i & 1][j] = (b_ij[~i & 1][j] + b_ij[i & 1][j-1] + mod - b_ij[~i & 1][j-1]) % mod;
for(int k = 1; k <= n; k++) {
a_Ijk[i & 1][j][k] = a_Ijk[~i & 1][j][k];
ll dp = 0;
if(a[i] <= j && j < b[i]) {
ll len = cmp[j] - cmp[j-1];
if(k == 1) {
dp = (1 + b_ij[~i & 1][j-1]) * len % mod;
}else{
dp = a_Ijk[~i & 1][j][k-1] * (len - k + 1) % mod * inv[k] % mod;
}
}
(a_Ijk[i & 1][j][k] += dp) %= mod;
b_ij[i & 1][j] += dp;
ans += dp;
}
b_ij[i & 1][j] %= mod;
}
}
cout << ans % mod << endl;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
boat.cpp:56:9: note: in expansion of macro 'debug'
56 | debug("inv[%d] = %lld\n", i, inv[i]);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
574 ms |
8240 KB |
Output is correct |
2 |
Correct |
568 ms |
8236 KB |
Output is correct |
3 |
Correct |
563 ms |
8236 KB |
Output is correct |
4 |
Correct |
566 ms |
8260 KB |
Output is correct |
5 |
Correct |
571 ms |
8240 KB |
Output is correct |
6 |
Correct |
553 ms |
8260 KB |
Output is correct |
7 |
Correct |
568 ms |
8244 KB |
Output is correct |
8 |
Correct |
552 ms |
8140 KB |
Output is correct |
9 |
Correct |
555 ms |
8352 KB |
Output is correct |
10 |
Correct |
564 ms |
8260 KB |
Output is correct |
11 |
Correct |
563 ms |
8248 KB |
Output is correct |
12 |
Correct |
566 ms |
8260 KB |
Output is correct |
13 |
Correct |
562 ms |
8232 KB |
Output is correct |
14 |
Correct |
571 ms |
8240 KB |
Output is correct |
15 |
Correct |
558 ms |
8232 KB |
Output is correct |
16 |
Correct |
102 ms |
1732 KB |
Output is correct |
17 |
Correct |
127 ms |
1832 KB |
Output is correct |
18 |
Correct |
98 ms |
1768 KB |
Output is correct |
19 |
Correct |
105 ms |
1740 KB |
Output is correct |
20 |
Correct |
106 ms |
1740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
574 ms |
8240 KB |
Output is correct |
2 |
Correct |
568 ms |
8236 KB |
Output is correct |
3 |
Correct |
563 ms |
8236 KB |
Output is correct |
4 |
Correct |
566 ms |
8260 KB |
Output is correct |
5 |
Correct |
571 ms |
8240 KB |
Output is correct |
6 |
Correct |
553 ms |
8260 KB |
Output is correct |
7 |
Correct |
568 ms |
8244 KB |
Output is correct |
8 |
Correct |
552 ms |
8140 KB |
Output is correct |
9 |
Correct |
555 ms |
8352 KB |
Output is correct |
10 |
Correct |
564 ms |
8260 KB |
Output is correct |
11 |
Correct |
563 ms |
8248 KB |
Output is correct |
12 |
Correct |
566 ms |
8260 KB |
Output is correct |
13 |
Correct |
562 ms |
8232 KB |
Output is correct |
14 |
Correct |
571 ms |
8240 KB |
Output is correct |
15 |
Correct |
558 ms |
8232 KB |
Output is correct |
16 |
Correct |
102 ms |
1732 KB |
Output is correct |
17 |
Correct |
127 ms |
1832 KB |
Output is correct |
18 |
Correct |
98 ms |
1768 KB |
Output is correct |
19 |
Correct |
105 ms |
1740 KB |
Output is correct |
20 |
Correct |
106 ms |
1740 KB |
Output is correct |
21 |
Correct |
1030 ms |
7544 KB |
Output is correct |
22 |
Correct |
1031 ms |
7636 KB |
Output is correct |
23 |
Correct |
1004 ms |
7500 KB |
Output is correct |
24 |
Correct |
1020 ms |
7444 KB |
Output is correct |
25 |
Correct |
1020 ms |
7488 KB |
Output is correct |
26 |
Correct |
1263 ms |
7292 KB |
Output is correct |
27 |
Correct |
1244 ms |
7416 KB |
Output is correct |
28 |
Correct |
1244 ms |
7364 KB |
Output is correct |
29 |
Correct |
1222 ms |
7260 KB |
Output is correct |
30 |
Correct |
596 ms |
8140 KB |
Output is correct |
31 |
Correct |
597 ms |
8260 KB |
Output is correct |
32 |
Correct |
575 ms |
8260 KB |
Output is correct |
33 |
Correct |
567 ms |
8236 KB |
Output is correct |
34 |
Correct |
580 ms |
8216 KB |
Output is correct |
35 |
Correct |
570 ms |
8228 KB |
Output is correct |
36 |
Correct |
568 ms |
8140 KB |
Output is correct |
37 |
Correct |
570 ms |
8220 KB |
Output is correct |
38 |
Correct |
574 ms |
8208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1920 KB |
Output is correct |
2 |
Correct |
9 ms |
1924 KB |
Output is correct |
3 |
Correct |
11 ms |
1920 KB |
Output is correct |
4 |
Correct |
10 ms |
1868 KB |
Output is correct |
5 |
Correct |
11 ms |
1924 KB |
Output is correct |
6 |
Correct |
14 ms |
1868 KB |
Output is correct |
7 |
Correct |
13 ms |
1920 KB |
Output is correct |
8 |
Correct |
14 ms |
1868 KB |
Output is correct |
9 |
Correct |
14 ms |
1920 KB |
Output is correct |
10 |
Correct |
14 ms |
1924 KB |
Output is correct |
11 |
Correct |
11 ms |
1920 KB |
Output is correct |
12 |
Correct |
10 ms |
1868 KB |
Output is correct |
13 |
Correct |
10 ms |
1916 KB |
Output is correct |
14 |
Correct |
10 ms |
1868 KB |
Output is correct |
15 |
Correct |
10 ms |
1916 KB |
Output is correct |
16 |
Correct |
7 ms |
1228 KB |
Output is correct |
17 |
Correct |
6 ms |
1228 KB |
Output is correct |
18 |
Correct |
7 ms |
1236 KB |
Output is correct |
19 |
Correct |
7 ms |
1228 KB |
Output is correct |
20 |
Correct |
6 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
574 ms |
8240 KB |
Output is correct |
2 |
Correct |
568 ms |
8236 KB |
Output is correct |
3 |
Correct |
563 ms |
8236 KB |
Output is correct |
4 |
Correct |
566 ms |
8260 KB |
Output is correct |
5 |
Correct |
571 ms |
8240 KB |
Output is correct |
6 |
Correct |
553 ms |
8260 KB |
Output is correct |
7 |
Correct |
568 ms |
8244 KB |
Output is correct |
8 |
Correct |
552 ms |
8140 KB |
Output is correct |
9 |
Correct |
555 ms |
8352 KB |
Output is correct |
10 |
Correct |
564 ms |
8260 KB |
Output is correct |
11 |
Correct |
563 ms |
8248 KB |
Output is correct |
12 |
Correct |
566 ms |
8260 KB |
Output is correct |
13 |
Correct |
562 ms |
8232 KB |
Output is correct |
14 |
Correct |
571 ms |
8240 KB |
Output is correct |
15 |
Correct |
558 ms |
8232 KB |
Output is correct |
16 |
Correct |
102 ms |
1732 KB |
Output is correct |
17 |
Correct |
127 ms |
1832 KB |
Output is correct |
18 |
Correct |
98 ms |
1768 KB |
Output is correct |
19 |
Correct |
105 ms |
1740 KB |
Output is correct |
20 |
Correct |
106 ms |
1740 KB |
Output is correct |
21 |
Correct |
1030 ms |
7544 KB |
Output is correct |
22 |
Correct |
1031 ms |
7636 KB |
Output is correct |
23 |
Correct |
1004 ms |
7500 KB |
Output is correct |
24 |
Correct |
1020 ms |
7444 KB |
Output is correct |
25 |
Correct |
1020 ms |
7488 KB |
Output is correct |
26 |
Correct |
1263 ms |
7292 KB |
Output is correct |
27 |
Correct |
1244 ms |
7416 KB |
Output is correct |
28 |
Correct |
1244 ms |
7364 KB |
Output is correct |
29 |
Correct |
1222 ms |
7260 KB |
Output is correct |
30 |
Correct |
596 ms |
8140 KB |
Output is correct |
31 |
Correct |
597 ms |
8260 KB |
Output is correct |
32 |
Correct |
575 ms |
8260 KB |
Output is correct |
33 |
Correct |
567 ms |
8236 KB |
Output is correct |
34 |
Correct |
580 ms |
8216 KB |
Output is correct |
35 |
Correct |
570 ms |
8228 KB |
Output is correct |
36 |
Correct |
568 ms |
8140 KB |
Output is correct |
37 |
Correct |
570 ms |
8220 KB |
Output is correct |
38 |
Correct |
574 ms |
8208 KB |
Output is correct |
39 |
Correct |
10 ms |
1920 KB |
Output is correct |
40 |
Correct |
9 ms |
1924 KB |
Output is correct |
41 |
Correct |
11 ms |
1920 KB |
Output is correct |
42 |
Correct |
10 ms |
1868 KB |
Output is correct |
43 |
Correct |
11 ms |
1924 KB |
Output is correct |
44 |
Correct |
14 ms |
1868 KB |
Output is correct |
45 |
Correct |
13 ms |
1920 KB |
Output is correct |
46 |
Correct |
14 ms |
1868 KB |
Output is correct |
47 |
Correct |
14 ms |
1920 KB |
Output is correct |
48 |
Correct |
14 ms |
1924 KB |
Output is correct |
49 |
Correct |
11 ms |
1920 KB |
Output is correct |
50 |
Correct |
10 ms |
1868 KB |
Output is correct |
51 |
Correct |
10 ms |
1916 KB |
Output is correct |
52 |
Correct |
10 ms |
1868 KB |
Output is correct |
53 |
Correct |
10 ms |
1916 KB |
Output is correct |
54 |
Correct |
7 ms |
1228 KB |
Output is correct |
55 |
Correct |
6 ms |
1228 KB |
Output is correct |
56 |
Correct |
7 ms |
1236 KB |
Output is correct |
57 |
Correct |
7 ms |
1228 KB |
Output is correct |
58 |
Correct |
6 ms |
1100 KB |
Output is correct |
59 |
Correct |
1149 ms |
8248 KB |
Output is correct |
60 |
Correct |
1111 ms |
8244 KB |
Output is correct |
61 |
Correct |
1091 ms |
8268 KB |
Output is correct |
62 |
Correct |
1150 ms |
8268 KB |
Output is correct |
63 |
Correct |
1128 ms |
8268 KB |
Output is correct |
64 |
Correct |
1423 ms |
8300 KB |
Output is correct |
65 |
Correct |
1427 ms |
8248 KB |
Output is correct |
66 |
Correct |
1414 ms |
8256 KB |
Output is correct |
67 |
Correct |
1411 ms |
8248 KB |
Output is correct |
68 |
Correct |
1415 ms |
8248 KB |
Output is correct |
69 |
Correct |
1101 ms |
8252 KB |
Output is correct |
70 |
Correct |
1118 ms |
8268 KB |
Output is correct |
71 |
Correct |
1140 ms |
8244 KB |
Output is correct |
72 |
Correct |
1127 ms |
8248 KB |
Output is correct |
73 |
Correct |
1110 ms |
8244 KB |
Output is correct |
74 |
Correct |
213 ms |
1780 KB |
Output is correct |
75 |
Correct |
217 ms |
1808 KB |
Output is correct |
76 |
Correct |
225 ms |
1740 KB |
Output is correct |
77 |
Correct |
224 ms |
1740 KB |
Output is correct |
78 |
Correct |
220 ms |
1868 KB |
Output is correct |