# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
877113 |
2023-11-22T22:11:19 Z |
AMnu |
Boat (APIO16_boat) |
C++14 |
|
2000 ms |
6768 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e2+5, MOD = 1e9+7;
int N, M, A[MAXN], B[MAXN], S[2*MAXN];
long long dp[2*MAXN][MAXN], pref[2*MAXN][MAXN], inv[MAXN];
long long comb(int x,int y) {
long long ret = inv[y];
for (int i=0; i<y; i++) {
ret = ret*(x-i)%MOD;
}
return ret;
}
int main() {
cin >> N;
for (int i=1; i<=N; i++) {
cin >> A[i] >> B[i];
S[2*i-2] = A[i];
S[2*i-1] = B[i]+1;
}
sort(S,S+2*N);
for (int i=1; i<2*N; i++) {
if (S[i] != S[M]) {
M++;
S[M] = S[i];
}
}
inv[1] = 1;
for (int i=2; i<=N; i++) {
inv[i] = MOD - inv[N%i]*(N/i)%MOD;
}
for (int i=2; i<=N; i++) {
inv[i] = inv[i-1]*inv[i]%MOD;
}
dp[0][0] = 1;
for (int i=0; i<=N; i++) {
pref[0][i] = 1;
}
for (int i=1; i<=M; i++) {
pref[i][0] = 1;
for (int j=1; j<=N; j++) {
if (A[j]<=S[i-1] && S[i]-1<=B[j]) {
dp[i][j] = comb(S[i]-S[i-1],1)*pref[i-1][j-1]%MOD;
int cnt = 0;
for (int k=j-1; k>=1; k--) {
if (A[k]<=S[i-1] && S[i]<=B[k]) {
for (int l=0; l<=cnt; l++) {
dp[i][j] += comb(S[i]-S[i-1],l+2)*comb(cnt,l)%MOD * dp[i-1][k-1];
dp[i][j] %= MOD;
}
cnt++;
}
}
}
pref[i][j] = (dp[i][j] + pref[i][j-1] + pref[i-1][j] + MOD-pref[i-1][j-1]) % MOD;
}
}
cout << (pref[M][N]+MOD-1) % MOD << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6488 KB |
Output is correct |
2 |
Correct |
5 ms |
6492 KB |
Output is correct |
3 |
Correct |
5 ms |
6492 KB |
Output is correct |
4 |
Correct |
4 ms |
6488 KB |
Output is correct |
5 |
Correct |
5 ms |
6488 KB |
Output is correct |
6 |
Correct |
4 ms |
6604 KB |
Output is correct |
7 |
Correct |
4 ms |
6488 KB |
Output is correct |
8 |
Correct |
5 ms |
6492 KB |
Output is correct |
9 |
Correct |
5 ms |
6488 KB |
Output is correct |
10 |
Correct |
4 ms |
6492 KB |
Output is correct |
11 |
Correct |
4 ms |
6492 KB |
Output is correct |
12 |
Correct |
4 ms |
6528 KB |
Output is correct |
13 |
Correct |
4 ms |
6492 KB |
Output is correct |
14 |
Correct |
5 ms |
6492 KB |
Output is correct |
15 |
Correct |
5 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
4952 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6488 KB |
Output is correct |
2 |
Correct |
5 ms |
6492 KB |
Output is correct |
3 |
Correct |
5 ms |
6492 KB |
Output is correct |
4 |
Correct |
4 ms |
6488 KB |
Output is correct |
5 |
Correct |
5 ms |
6488 KB |
Output is correct |
6 |
Correct |
4 ms |
6604 KB |
Output is correct |
7 |
Correct |
4 ms |
6488 KB |
Output is correct |
8 |
Correct |
5 ms |
6492 KB |
Output is correct |
9 |
Correct |
5 ms |
6488 KB |
Output is correct |
10 |
Correct |
4 ms |
6492 KB |
Output is correct |
11 |
Correct |
4 ms |
6492 KB |
Output is correct |
12 |
Correct |
4 ms |
6528 KB |
Output is correct |
13 |
Correct |
4 ms |
6492 KB |
Output is correct |
14 |
Correct |
5 ms |
6492 KB |
Output is correct |
15 |
Correct |
5 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
4952 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Execution timed out |
2028 ms |
5248 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
6768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6488 KB |
Output is correct |
2 |
Correct |
5 ms |
6492 KB |
Output is correct |
3 |
Correct |
5 ms |
6492 KB |
Output is correct |
4 |
Correct |
4 ms |
6488 KB |
Output is correct |
5 |
Correct |
5 ms |
6488 KB |
Output is correct |
6 |
Correct |
4 ms |
6604 KB |
Output is correct |
7 |
Correct |
4 ms |
6488 KB |
Output is correct |
8 |
Correct |
5 ms |
6492 KB |
Output is correct |
9 |
Correct |
5 ms |
6488 KB |
Output is correct |
10 |
Correct |
4 ms |
6492 KB |
Output is correct |
11 |
Correct |
4 ms |
6492 KB |
Output is correct |
12 |
Correct |
4 ms |
6528 KB |
Output is correct |
13 |
Correct |
4 ms |
6492 KB |
Output is correct |
14 |
Correct |
5 ms |
6492 KB |
Output is correct |
15 |
Correct |
5 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
4952 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Execution timed out |
2028 ms |
5248 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |