# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
447785 |
2021-07-27T14:09:04 Z |
dutch |
Boat (APIO16_boat) |
C++17 |
|
15 ms |
8208 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define valid(x, y) (a[x] <= pts[y] && pts[y+1] <= b[x]+1)
const int MOD = 1e9+7, LIM = 501;
int modInverse(int x){
int r = 1, p = (MOD - 2) * 2;
for(int y=x; p/=2; y=(y*y) % MOD)
if(p & 1) r = (r*y) % MOD;
return r;
}
int n, a[LIM], b[LIM], dp[LIM][LIM*2], F[LIM], invF[LIM], C[LIM*2][LIM];
vector<int> pts;
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=0; i<n; ++i){
cin >> a[i] >> b[i];
pts.push_back(a[i]);
pts.push_back(b[i]+1);
}
sort(pts.begin(), pts.end());
pts.resize(unique(pts.begin(), pts.end()) - pts.begin());
int m = size(pts) - 1, ans = 0;
F[0] = invF[0] = 1;
for(int i=1; i<=n; ++i){
F[i] = (F[i-1] * i) % MOD;
invF[i] = modInverse(F[i]);
}
for(int i=0; i<m; ++i){
int diff = pts[i+1] - pts[i];
int p = 1;
for(int j=1; j<=n; ++j){
(p *= diff - j + 1) %= MOD;
C[i][j] = (p * invF[j]) % MOD;
}
}
for(int i=0; i<n; ++i){
for(int k=0; k<m; ++k){
if(!valid(i, k)) continue;
int cnt = 1, p = C[k][1];
for(int j=i; --j>=0; ){
if(k) (dp[i][k] += dp[j][k-1] * cnt) %= MOD;
if(valid(j, k)) p += C[k][++cnt];
}
(dp[i][k] += p) %= MOD;
(ans += dp[i][k]) %= MOD;
}
for(int k=1; k<m; ++k) (dp[i][k] += dp[i][k-1]) %= MOD;
}
cout << (ans % MOD + MOD) % MOD;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8140 KB |
Output is correct |
2 |
Correct |
15 ms |
8140 KB |
Output is correct |
3 |
Correct |
13 ms |
8140 KB |
Output is correct |
4 |
Correct |
14 ms |
8184 KB |
Output is correct |
5 |
Correct |
13 ms |
8160 KB |
Output is correct |
6 |
Correct |
13 ms |
8140 KB |
Output is correct |
7 |
Correct |
13 ms |
8108 KB |
Output is correct |
8 |
Correct |
13 ms |
8140 KB |
Output is correct |
9 |
Correct |
12 ms |
8140 KB |
Output is correct |
10 |
Correct |
12 ms |
8140 KB |
Output is correct |
11 |
Correct |
12 ms |
8208 KB |
Output is correct |
12 |
Correct |
13 ms |
8148 KB |
Output is correct |
13 |
Correct |
13 ms |
8152 KB |
Output is correct |
14 |
Correct |
13 ms |
8132 KB |
Output is correct |
15 |
Correct |
13 ms |
8136 KB |
Output is correct |
16 |
Incorrect |
5 ms |
3660 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8140 KB |
Output is correct |
2 |
Correct |
15 ms |
8140 KB |
Output is correct |
3 |
Correct |
13 ms |
8140 KB |
Output is correct |
4 |
Correct |
14 ms |
8184 KB |
Output is correct |
5 |
Correct |
13 ms |
8160 KB |
Output is correct |
6 |
Correct |
13 ms |
8140 KB |
Output is correct |
7 |
Correct |
13 ms |
8108 KB |
Output is correct |
8 |
Correct |
13 ms |
8140 KB |
Output is correct |
9 |
Correct |
12 ms |
8140 KB |
Output is correct |
10 |
Correct |
12 ms |
8140 KB |
Output is correct |
11 |
Correct |
12 ms |
8208 KB |
Output is correct |
12 |
Correct |
13 ms |
8148 KB |
Output is correct |
13 |
Correct |
13 ms |
8152 KB |
Output is correct |
14 |
Correct |
13 ms |
8132 KB |
Output is correct |
15 |
Correct |
13 ms |
8136 KB |
Output is correct |
16 |
Incorrect |
5 ms |
3660 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8140 KB |
Output is correct |
2 |
Correct |
15 ms |
8140 KB |
Output is correct |
3 |
Correct |
13 ms |
8140 KB |
Output is correct |
4 |
Correct |
14 ms |
8184 KB |
Output is correct |
5 |
Correct |
13 ms |
8160 KB |
Output is correct |
6 |
Correct |
13 ms |
8140 KB |
Output is correct |
7 |
Correct |
13 ms |
8108 KB |
Output is correct |
8 |
Correct |
13 ms |
8140 KB |
Output is correct |
9 |
Correct |
12 ms |
8140 KB |
Output is correct |
10 |
Correct |
12 ms |
8140 KB |
Output is correct |
11 |
Correct |
12 ms |
8208 KB |
Output is correct |
12 |
Correct |
13 ms |
8148 KB |
Output is correct |
13 |
Correct |
13 ms |
8152 KB |
Output is correct |
14 |
Correct |
13 ms |
8132 KB |
Output is correct |
15 |
Correct |
13 ms |
8136 KB |
Output is correct |
16 |
Incorrect |
5 ms |
3660 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |