#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define int ll
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()
ull binexp(ull base, ull pow, ull M=MOD){
ull res = 1;
while(pow){
if(pow & 1) res *= base;
pow >>= 1, base *= base;
if(M) base %= M, res %= M;
}
return res;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
vi inv(510);
for(int x = 0; x < 510; x++)
inv[x] = binexp(x, MOD-2);
int N; cin >> N;
vii A(N+1); vi B;
for(int x = 1; x <= N; x++){
cin >> A[x].first >> A[x].second;
A[x].second++;
B.push_back(A[x].first); B.push_back(A[x].second);
}
sort(all(B));
vector<vvi> dp(2, vvi(B.size(), vi(N+1)));
int prev = 0, curr = 1;
for(int c = 1; c < B.size(); c++)
dp[prev][c][0] = 1;
for(int x = 1; x <= N; x++){
dp[curr][0][0] = 1;
for(int c = 1; c < B.size(); c++){
// j = 0 case
dp[curr][c][0] = 0;
for(auto val : dp[curr][c-1])
dp[curr][c][0] += val, dp[curr][c][0] %= MOD;
for(int j = 1; j <= min(x, B[c]-B[c-1]); j++){
dp[curr][c][j] = dp[prev][c][j];
if(A[x].first <= B[c-1] and B[c] <= A[x].second){
int val = (B[c]-B[c-1]-j+1)*inv[j]; val %= MOD;
dp[curr][c][j] += (dp[prev][c][j-1]*val)%MOD; dp[curr][c][j] %= MOD;
}
}
}
swap(prev, curr);
}
int ans = 0;
for(auto val : dp[prev][B.size()-1])
ans += val, ans %= MOD;
cout << (ans-1+MOD)%MOD << endl;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:52:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int c = 1; c < B.size(); c++)
| ~~^~~~~~~~~~
boat.cpp:57:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int c = 1; c < B.size(); c++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1264 ms |
12176 KB |
Output is correct |
2 |
Correct |
1286 ms |
12176 KB |
Output is correct |
3 |
Correct |
1270 ms |
12176 KB |
Output is correct |
4 |
Correct |
1278 ms |
12192 KB |
Output is correct |
5 |
Correct |
1247 ms |
12228 KB |
Output is correct |
6 |
Correct |
1295 ms |
12180 KB |
Output is correct |
7 |
Correct |
1272 ms |
12184 KB |
Output is correct |
8 |
Correct |
1260 ms |
12184 KB |
Output is correct |
9 |
Correct |
1258 ms |
12228 KB |
Output is correct |
10 |
Correct |
1282 ms |
12176 KB |
Output is correct |
11 |
Correct |
1273 ms |
12176 KB |
Output is correct |
12 |
Correct |
1274 ms |
12184 KB |
Output is correct |
13 |
Correct |
1258 ms |
12228 KB |
Output is correct |
14 |
Correct |
1253 ms |
12176 KB |
Output is correct |
15 |
Correct |
1284 ms |
12180 KB |
Output is correct |
16 |
Correct |
1169 ms |
12228 KB |
Output is correct |
17 |
Correct |
1165 ms |
12180 KB |
Output is correct |
18 |
Correct |
1174 ms |
12108 KB |
Output is correct |
19 |
Correct |
1184 ms |
12180 KB |
Output is correct |
20 |
Correct |
1171 ms |
12108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1264 ms |
12176 KB |
Output is correct |
2 |
Correct |
1286 ms |
12176 KB |
Output is correct |
3 |
Correct |
1270 ms |
12176 KB |
Output is correct |
4 |
Correct |
1278 ms |
12192 KB |
Output is correct |
5 |
Correct |
1247 ms |
12228 KB |
Output is correct |
6 |
Correct |
1295 ms |
12180 KB |
Output is correct |
7 |
Correct |
1272 ms |
12184 KB |
Output is correct |
8 |
Correct |
1260 ms |
12184 KB |
Output is correct |
9 |
Correct |
1258 ms |
12228 KB |
Output is correct |
10 |
Correct |
1282 ms |
12176 KB |
Output is correct |
11 |
Correct |
1273 ms |
12176 KB |
Output is correct |
12 |
Correct |
1274 ms |
12184 KB |
Output is correct |
13 |
Correct |
1258 ms |
12228 KB |
Output is correct |
14 |
Correct |
1253 ms |
12176 KB |
Output is correct |
15 |
Correct |
1284 ms |
12180 KB |
Output is correct |
16 |
Correct |
1169 ms |
12228 KB |
Output is correct |
17 |
Correct |
1165 ms |
12180 KB |
Output is correct |
18 |
Correct |
1174 ms |
12108 KB |
Output is correct |
19 |
Correct |
1184 ms |
12180 KB |
Output is correct |
20 |
Correct |
1171 ms |
12108 KB |
Output is correct |
21 |
Correct |
1170 ms |
12172 KB |
Output is correct |
22 |
Correct |
1164 ms |
12188 KB |
Output is correct |
23 |
Correct |
1170 ms |
12184 KB |
Output is correct |
24 |
Correct |
1159 ms |
12184 KB |
Output is correct |
25 |
Correct |
1171 ms |
12184 KB |
Output is correct |
26 |
Correct |
1160 ms |
12204 KB |
Output is correct |
27 |
Correct |
1168 ms |
12228 KB |
Output is correct |
28 |
Correct |
1169 ms |
12228 KB |
Output is correct |
29 |
Correct |
1181 ms |
12200 KB |
Output is correct |
30 |
Correct |
1259 ms |
12192 KB |
Output is correct |
31 |
Correct |
1255 ms |
12228 KB |
Output is correct |
32 |
Correct |
1261 ms |
12228 KB |
Output is correct |
33 |
Correct |
1250 ms |
12204 KB |
Output is correct |
34 |
Correct |
1270 ms |
12188 KB |
Output is correct |
35 |
Correct |
1251 ms |
12192 KB |
Output is correct |
36 |
Correct |
1247 ms |
12228 KB |
Output is correct |
37 |
Correct |
1260 ms |
12192 KB |
Output is correct |
38 |
Correct |
1250 ms |
12196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
716 KB |
Output is correct |
2 |
Correct |
14 ms |
812 KB |
Output is correct |
3 |
Correct |
14 ms |
844 KB |
Output is correct |
4 |
Correct |
14 ms |
716 KB |
Output is correct |
5 |
Correct |
14 ms |
812 KB |
Output is correct |
6 |
Correct |
15 ms |
716 KB |
Output is correct |
7 |
Correct |
15 ms |
812 KB |
Output is correct |
8 |
Correct |
16 ms |
716 KB |
Output is correct |
9 |
Correct |
15 ms |
816 KB |
Output is correct |
10 |
Correct |
15 ms |
808 KB |
Output is correct |
11 |
Correct |
15 ms |
812 KB |
Output is correct |
12 |
Correct |
14 ms |
820 KB |
Output is correct |
13 |
Correct |
14 ms |
808 KB |
Output is correct |
14 |
Correct |
14 ms |
812 KB |
Output is correct |
15 |
Correct |
14 ms |
716 KB |
Output is correct |
16 |
Correct |
12 ms |
716 KB |
Output is correct |
17 |
Correct |
12 ms |
844 KB |
Output is correct |
18 |
Correct |
12 ms |
812 KB |
Output is correct |
19 |
Correct |
12 ms |
808 KB |
Output is correct |
20 |
Correct |
12 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1264 ms |
12176 KB |
Output is correct |
2 |
Correct |
1286 ms |
12176 KB |
Output is correct |
3 |
Correct |
1270 ms |
12176 KB |
Output is correct |
4 |
Correct |
1278 ms |
12192 KB |
Output is correct |
5 |
Correct |
1247 ms |
12228 KB |
Output is correct |
6 |
Correct |
1295 ms |
12180 KB |
Output is correct |
7 |
Correct |
1272 ms |
12184 KB |
Output is correct |
8 |
Correct |
1260 ms |
12184 KB |
Output is correct |
9 |
Correct |
1258 ms |
12228 KB |
Output is correct |
10 |
Correct |
1282 ms |
12176 KB |
Output is correct |
11 |
Correct |
1273 ms |
12176 KB |
Output is correct |
12 |
Correct |
1274 ms |
12184 KB |
Output is correct |
13 |
Correct |
1258 ms |
12228 KB |
Output is correct |
14 |
Correct |
1253 ms |
12176 KB |
Output is correct |
15 |
Correct |
1284 ms |
12180 KB |
Output is correct |
16 |
Correct |
1169 ms |
12228 KB |
Output is correct |
17 |
Correct |
1165 ms |
12180 KB |
Output is correct |
18 |
Correct |
1174 ms |
12108 KB |
Output is correct |
19 |
Correct |
1184 ms |
12180 KB |
Output is correct |
20 |
Correct |
1171 ms |
12108 KB |
Output is correct |
21 |
Correct |
1170 ms |
12172 KB |
Output is correct |
22 |
Correct |
1164 ms |
12188 KB |
Output is correct |
23 |
Correct |
1170 ms |
12184 KB |
Output is correct |
24 |
Correct |
1159 ms |
12184 KB |
Output is correct |
25 |
Correct |
1171 ms |
12184 KB |
Output is correct |
26 |
Correct |
1160 ms |
12204 KB |
Output is correct |
27 |
Correct |
1168 ms |
12228 KB |
Output is correct |
28 |
Correct |
1169 ms |
12228 KB |
Output is correct |
29 |
Correct |
1181 ms |
12200 KB |
Output is correct |
30 |
Correct |
1259 ms |
12192 KB |
Output is correct |
31 |
Correct |
1255 ms |
12228 KB |
Output is correct |
32 |
Correct |
1261 ms |
12228 KB |
Output is correct |
33 |
Correct |
1250 ms |
12204 KB |
Output is correct |
34 |
Correct |
1270 ms |
12188 KB |
Output is correct |
35 |
Correct |
1251 ms |
12192 KB |
Output is correct |
36 |
Correct |
1247 ms |
12228 KB |
Output is correct |
37 |
Correct |
1260 ms |
12192 KB |
Output is correct |
38 |
Correct |
1250 ms |
12196 KB |
Output is correct |
39 |
Correct |
14 ms |
716 KB |
Output is correct |
40 |
Correct |
14 ms |
812 KB |
Output is correct |
41 |
Correct |
14 ms |
844 KB |
Output is correct |
42 |
Correct |
14 ms |
716 KB |
Output is correct |
43 |
Correct |
14 ms |
812 KB |
Output is correct |
44 |
Correct |
15 ms |
716 KB |
Output is correct |
45 |
Correct |
15 ms |
812 KB |
Output is correct |
46 |
Correct |
16 ms |
716 KB |
Output is correct |
47 |
Correct |
15 ms |
816 KB |
Output is correct |
48 |
Correct |
15 ms |
808 KB |
Output is correct |
49 |
Correct |
15 ms |
812 KB |
Output is correct |
50 |
Correct |
14 ms |
820 KB |
Output is correct |
51 |
Correct |
14 ms |
808 KB |
Output is correct |
52 |
Correct |
14 ms |
812 KB |
Output is correct |
53 |
Correct |
14 ms |
716 KB |
Output is correct |
54 |
Correct |
12 ms |
716 KB |
Output is correct |
55 |
Correct |
12 ms |
844 KB |
Output is correct |
56 |
Correct |
12 ms |
812 KB |
Output is correct |
57 |
Correct |
12 ms |
808 KB |
Output is correct |
58 |
Correct |
12 ms |
716 KB |
Output is correct |
59 |
Correct |
1668 ms |
12188 KB |
Output is correct |
60 |
Correct |
1654 ms |
12188 KB |
Output is correct |
61 |
Correct |
1643 ms |
12108 KB |
Output is correct |
62 |
Correct |
1670 ms |
12188 KB |
Output is correct |
63 |
Correct |
1654 ms |
12232 KB |
Output is correct |
64 |
Correct |
1812 ms |
12232 KB |
Output is correct |
65 |
Correct |
1807 ms |
12192 KB |
Output is correct |
66 |
Correct |
1819 ms |
12204 KB |
Output is correct |
67 |
Correct |
1813 ms |
12196 KB |
Output is correct |
68 |
Correct |
1809 ms |
12192 KB |
Output is correct |
69 |
Correct |
1621 ms |
12188 KB |
Output is correct |
70 |
Correct |
1597 ms |
12232 KB |
Output is correct |
71 |
Correct |
1623 ms |
12200 KB |
Output is correct |
72 |
Correct |
1591 ms |
12192 KB |
Output is correct |
73 |
Correct |
1612 ms |
12228 KB |
Output is correct |
74 |
Correct |
1196 ms |
12196 KB |
Output is correct |
75 |
Correct |
1207 ms |
12192 KB |
Output is correct |
76 |
Correct |
1203 ms |
12228 KB |
Output is correct |
77 |
Correct |
1220 ms |
12184 KB |
Output is correct |
78 |
Correct |
1195 ms |
12196 KB |
Output is correct |