# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
161114 |
2019-10-31T14:20:48 Z |
pzdba |
Boat (APIO16_boat) |
C++14 |
|
1726 ms |
10448 KB |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int dp[501][1001];
int tmp[1001][501];
int D[1001][501], C[1001][1001];
int sum[1001][501];
vector<int> v;
int binPow(int a, int b){
int ans = 1;
while(b){
if(b%2 == 1) ans = ans*1ll*a%mod;
a = a*1ll*a%mod;
b/=2;
}
return ans;
}
int f[1001], inv[1001], a[501], b[501], l[501], r[501];
int ncr(int a, int b){
int l = v[a]-v[a-1];
if(b > l) return 0;
else if(b == l) return 1;
int mn = min(l-b, b);
return tmp[a][mn]*1ll*inv[mn]%mod;
}
int main(){
C[0][0] = 1;
for(int i=1;i<=1000;i++){
C[i][0] = C[i][i] = 1;
for(int j=1;j<i;j++){
C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
}
}
f[0] = 1;
for(int i=1;i<=1000;i++) f[i] = f[i-1]*1ll*i%mod;
for(int i=0;i<=1000;i++) inv[i] = binPow(f[i], mod-2);
int n;
scanf("%d", &n);
for(int i=1;i<=n;i++){
scanf("%d%d", &a[i], &b[i]);
v.push_back(a[i]-1);
v.push_back(b[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(int i=1;i<=n;i++){
l[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
r[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
}
// for(int i=1;i<v.size();i++){
// for(int j=1;j<=n;j++){
// D[i][j] = ncr(v[i]-v[i-1], j);
// for(int l=0;l<j;l++){
// sum[i][j] = (sum[i][j] + D[i][l+1]*1ll*C[j-1][l])%mod;
// }
// }
// }
for(int j=1;j<v.size();j++){
for(int i=1;i<=n;i++){
if(i == 1) tmp[j][i] = v[j]-v[j-1];
else tmp[j][i] = tmp[j][i-1]*1ll*(v[j]-v[j-1]-i+1)%mod;
}
}
for(int j=0;j<=1000;j++) dp[0][j] = 1;
int ans = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<v.size();j++){
for(int l=0;l<i;l++){
sum[j][i] = (sum[j][i] + ncr(j, l+1)*1ll*C[i-1][l])%mod;
}
if(l[i] <= j && j <= r[i]){
int cnt = 0;
for(int k=i;k>=1;k--){
if(l[k] <= j && j <= r[k]) cnt++;
dp[i][j] = (dp[i][j] + dp[k-1][j-1]*1ll*sum[j][cnt])%mod;
}
}
dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
}
ans = (ans + dp[i][v.size()-1])%mod;
}
printf("%d\n", ans);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:60:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1;j<v.size();j++){
~^~~~~~~~~
boat.cpp:69:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1;j<v.size();j++){
~^~~~~~~~~
boat.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a[i], &b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
967 ms |
10448 KB |
Output is correct |
2 |
Correct |
955 ms |
10156 KB |
Output is correct |
3 |
Correct |
975 ms |
10284 KB |
Output is correct |
4 |
Correct |
971 ms |
10240 KB |
Output is correct |
5 |
Correct |
961 ms |
10224 KB |
Output is correct |
6 |
Correct |
974 ms |
10272 KB |
Output is correct |
7 |
Correct |
963 ms |
10360 KB |
Output is correct |
8 |
Correct |
959 ms |
10372 KB |
Output is correct |
9 |
Correct |
971 ms |
10192 KB |
Output is correct |
10 |
Correct |
960 ms |
10172 KB |
Output is correct |
11 |
Correct |
989 ms |
10200 KB |
Output is correct |
12 |
Correct |
979 ms |
10352 KB |
Output is correct |
13 |
Correct |
978 ms |
10236 KB |
Output is correct |
14 |
Correct |
951 ms |
10332 KB |
Output is correct |
15 |
Correct |
957 ms |
10328 KB |
Output is correct |
16 |
Correct |
174 ms |
6904 KB |
Output is correct |
17 |
Correct |
190 ms |
7004 KB |
Output is correct |
18 |
Correct |
180 ms |
7044 KB |
Output is correct |
19 |
Correct |
188 ms |
7064 KB |
Output is correct |
20 |
Correct |
182 ms |
6904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
967 ms |
10448 KB |
Output is correct |
2 |
Correct |
955 ms |
10156 KB |
Output is correct |
3 |
Correct |
975 ms |
10284 KB |
Output is correct |
4 |
Correct |
971 ms |
10240 KB |
Output is correct |
5 |
Correct |
961 ms |
10224 KB |
Output is correct |
6 |
Correct |
974 ms |
10272 KB |
Output is correct |
7 |
Correct |
963 ms |
10360 KB |
Output is correct |
8 |
Correct |
959 ms |
10372 KB |
Output is correct |
9 |
Correct |
971 ms |
10192 KB |
Output is correct |
10 |
Correct |
960 ms |
10172 KB |
Output is correct |
11 |
Correct |
989 ms |
10200 KB |
Output is correct |
12 |
Correct |
979 ms |
10352 KB |
Output is correct |
13 |
Correct |
978 ms |
10236 KB |
Output is correct |
14 |
Correct |
951 ms |
10332 KB |
Output is correct |
15 |
Correct |
957 ms |
10328 KB |
Output is correct |
16 |
Correct |
174 ms |
6904 KB |
Output is correct |
17 |
Correct |
190 ms |
7004 KB |
Output is correct |
18 |
Correct |
180 ms |
7044 KB |
Output is correct |
19 |
Correct |
188 ms |
7064 KB |
Output is correct |
20 |
Correct |
182 ms |
6904 KB |
Output is correct |
21 |
Correct |
1061 ms |
9904 KB |
Output is correct |
22 |
Correct |
1165 ms |
9884 KB |
Output is correct |
23 |
Correct |
1034 ms |
9844 KB |
Output is correct |
24 |
Correct |
1002 ms |
9976 KB |
Output is correct |
25 |
Correct |
1035 ms |
9848 KB |
Output is correct |
26 |
Correct |
1030 ms |
9776 KB |
Output is correct |
27 |
Correct |
1079 ms |
9848 KB |
Output is correct |
28 |
Correct |
1046 ms |
9804 KB |
Output is correct |
29 |
Correct |
1047 ms |
9688 KB |
Output is correct |
30 |
Correct |
977 ms |
10160 KB |
Output is correct |
31 |
Correct |
956 ms |
10208 KB |
Output is correct |
32 |
Correct |
964 ms |
10352 KB |
Output is correct |
33 |
Correct |
964 ms |
10360 KB |
Output is correct |
34 |
Correct |
946 ms |
10436 KB |
Output is correct |
35 |
Correct |
944 ms |
10120 KB |
Output is correct |
36 |
Correct |
986 ms |
10332 KB |
Output is correct |
37 |
Correct |
956 ms |
10192 KB |
Output is correct |
38 |
Correct |
970 ms |
10132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
5496 KB |
Output is correct |
2 |
Correct |
19 ms |
5496 KB |
Output is correct |
3 |
Correct |
20 ms |
5496 KB |
Output is correct |
4 |
Correct |
21 ms |
5496 KB |
Output is correct |
5 |
Correct |
18 ms |
5496 KB |
Output is correct |
6 |
Correct |
20 ms |
5496 KB |
Output is correct |
7 |
Correct |
20 ms |
5496 KB |
Output is correct |
8 |
Correct |
21 ms |
5496 KB |
Output is correct |
9 |
Correct |
21 ms |
5496 KB |
Output is correct |
10 |
Correct |
20 ms |
5504 KB |
Output is correct |
11 |
Correct |
21 ms |
5500 KB |
Output is correct |
12 |
Correct |
19 ms |
5496 KB |
Output is correct |
13 |
Correct |
20 ms |
5500 KB |
Output is correct |
14 |
Correct |
19 ms |
5496 KB |
Output is correct |
15 |
Correct |
20 ms |
5496 KB |
Output is correct |
16 |
Correct |
13 ms |
5112 KB |
Output is correct |
17 |
Correct |
14 ms |
5116 KB |
Output is correct |
18 |
Correct |
13 ms |
5112 KB |
Output is correct |
19 |
Correct |
13 ms |
5112 KB |
Output is correct |
20 |
Correct |
13 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
967 ms |
10448 KB |
Output is correct |
2 |
Correct |
955 ms |
10156 KB |
Output is correct |
3 |
Correct |
975 ms |
10284 KB |
Output is correct |
4 |
Correct |
971 ms |
10240 KB |
Output is correct |
5 |
Correct |
961 ms |
10224 KB |
Output is correct |
6 |
Correct |
974 ms |
10272 KB |
Output is correct |
7 |
Correct |
963 ms |
10360 KB |
Output is correct |
8 |
Correct |
959 ms |
10372 KB |
Output is correct |
9 |
Correct |
971 ms |
10192 KB |
Output is correct |
10 |
Correct |
960 ms |
10172 KB |
Output is correct |
11 |
Correct |
989 ms |
10200 KB |
Output is correct |
12 |
Correct |
979 ms |
10352 KB |
Output is correct |
13 |
Correct |
978 ms |
10236 KB |
Output is correct |
14 |
Correct |
951 ms |
10332 KB |
Output is correct |
15 |
Correct |
957 ms |
10328 KB |
Output is correct |
16 |
Correct |
174 ms |
6904 KB |
Output is correct |
17 |
Correct |
190 ms |
7004 KB |
Output is correct |
18 |
Correct |
180 ms |
7044 KB |
Output is correct |
19 |
Correct |
188 ms |
7064 KB |
Output is correct |
20 |
Correct |
182 ms |
6904 KB |
Output is correct |
21 |
Correct |
1061 ms |
9904 KB |
Output is correct |
22 |
Correct |
1165 ms |
9884 KB |
Output is correct |
23 |
Correct |
1034 ms |
9844 KB |
Output is correct |
24 |
Correct |
1002 ms |
9976 KB |
Output is correct |
25 |
Correct |
1035 ms |
9848 KB |
Output is correct |
26 |
Correct |
1030 ms |
9776 KB |
Output is correct |
27 |
Correct |
1079 ms |
9848 KB |
Output is correct |
28 |
Correct |
1046 ms |
9804 KB |
Output is correct |
29 |
Correct |
1047 ms |
9688 KB |
Output is correct |
30 |
Correct |
977 ms |
10160 KB |
Output is correct |
31 |
Correct |
956 ms |
10208 KB |
Output is correct |
32 |
Correct |
964 ms |
10352 KB |
Output is correct |
33 |
Correct |
964 ms |
10360 KB |
Output is correct |
34 |
Correct |
946 ms |
10436 KB |
Output is correct |
35 |
Correct |
944 ms |
10120 KB |
Output is correct |
36 |
Correct |
986 ms |
10332 KB |
Output is correct |
37 |
Correct |
956 ms |
10192 KB |
Output is correct |
38 |
Correct |
970 ms |
10132 KB |
Output is correct |
39 |
Correct |
21 ms |
5496 KB |
Output is correct |
40 |
Correct |
19 ms |
5496 KB |
Output is correct |
41 |
Correct |
20 ms |
5496 KB |
Output is correct |
42 |
Correct |
21 ms |
5496 KB |
Output is correct |
43 |
Correct |
18 ms |
5496 KB |
Output is correct |
44 |
Correct |
20 ms |
5496 KB |
Output is correct |
45 |
Correct |
20 ms |
5496 KB |
Output is correct |
46 |
Correct |
21 ms |
5496 KB |
Output is correct |
47 |
Correct |
21 ms |
5496 KB |
Output is correct |
48 |
Correct |
20 ms |
5504 KB |
Output is correct |
49 |
Correct |
21 ms |
5500 KB |
Output is correct |
50 |
Correct |
19 ms |
5496 KB |
Output is correct |
51 |
Correct |
20 ms |
5500 KB |
Output is correct |
52 |
Correct |
19 ms |
5496 KB |
Output is correct |
53 |
Correct |
20 ms |
5496 KB |
Output is correct |
54 |
Correct |
13 ms |
5112 KB |
Output is correct |
55 |
Correct |
14 ms |
5116 KB |
Output is correct |
56 |
Correct |
13 ms |
5112 KB |
Output is correct |
57 |
Correct |
13 ms |
5112 KB |
Output is correct |
58 |
Correct |
13 ms |
5112 KB |
Output is correct |
59 |
Correct |
1621 ms |
10424 KB |
Output is correct |
60 |
Correct |
1591 ms |
10356 KB |
Output is correct |
61 |
Correct |
1568 ms |
10380 KB |
Output is correct |
62 |
Correct |
1646 ms |
10340 KB |
Output is correct |
63 |
Correct |
1654 ms |
10260 KB |
Output is correct |
64 |
Correct |
1718 ms |
10324 KB |
Output is correct |
65 |
Correct |
1726 ms |
10352 KB |
Output is correct |
66 |
Correct |
1692 ms |
10256 KB |
Output is correct |
67 |
Correct |
1697 ms |
10236 KB |
Output is correct |
68 |
Correct |
1687 ms |
10372 KB |
Output is correct |
69 |
Correct |
1442 ms |
10276 KB |
Output is correct |
70 |
Correct |
1473 ms |
10292 KB |
Output is correct |
71 |
Correct |
1424 ms |
10372 KB |
Output is correct |
72 |
Correct |
1463 ms |
10240 KB |
Output is correct |
73 |
Correct |
1437 ms |
10272 KB |
Output is correct |
74 |
Correct |
246 ms |
6904 KB |
Output is correct |
75 |
Correct |
244 ms |
7036 KB |
Output is correct |
76 |
Correct |
247 ms |
7168 KB |
Output is correct |
77 |
Correct |
240 ms |
7032 KB |
Output is correct |
78 |
Correct |
242 ms |
7004 KB |
Output is correct |