# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
425320 |
2021-06-12T21:20:41 Z |
ksun48 |
Boat (APIO16_boat) |
C++14 |
|
1423 ms |
30388 KB |
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL n;
LL a[1100];
LL b[1100];
LL included[1100][1100];
LL length[1100];
LL dp[2][1100][1100];
LL lenchoose[1100][1100];
LL invlist[1100];
LL powmod(LL z1, LL e){
if(e == 0) return 1;
LL c = powmod(z1,e/2);
c = (c*c) % MOD;
if(e % 2 == 0) return c;
return (c*z1)%MOD;
}
LL inv(LL z1){
return powmod(z1,MOD-2) % MOD;
}
int main(){
set<LL> st;
cin >> n;
st.insert(0);
st.insert(1);
int t1 = 0;
for(int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
st.insert(a[i]);
st.insert(b[i]+1);
t1 += b[i]-a[i];
}
st.insert(1000000005);
st.insert(1000000006);
int cur = 0;
for(int i = 1; i < 1100; i++){
invlist[i] = inv(i);
}
/*if(t1 <= 1000000){
return 0;
}*/
while(st.size() >= 2){
set<LL>::iterator c = st.begin();
int l = *c;
c++;
int r = *c;
st.erase(st.begin());
included[0][cur] = 0;
included[n+1][cur] = 0;
length[cur] = r-l;
for(int i = 1; i <= n; i++){
if(a[i] <= l && r-1 <= b[i]){
included[i][cur] = 1;
} else {
included[i][cur] = 0;
}
}
cur++;
}
included[0][0] = 1;
included[n+1][cur-1] = 1;
dp[0][0][1] = 1;
for(int i = 0; i < cur; i++){
int l = length[i];
for(int j = 0; j < 510; j++){
if(j > l){
lenchoose[i][j] = 0;
} else if(j == 0){
lenchoose[i][j] = 1;
} else {
lenchoose[i][j] = lenchoose[i][j-1];
lenchoose[i][j] *= (LL)(l-j+1);
lenchoose[i][j] %= MOD;
lenchoose[i][j] *= invlist[j];
lenchoose[i][j] %= MOD;
}
}
}
for(int s = 0; s <= n; s++){
for(int j = 0; j < 1100; j++){
for(int k = 0; k < 510; k++){
dp[1-s%2][j][k] = 0;
}
}
LL r = 0;
for(int l = 1; l < cur; l++){
for(int k = 1; k <= cur && k <= 510; k++) if(dp[s%2][l-1][k] != 0){
r += lenchoose[l-1][k]*dp[s%2][l-1][k];
r %= MOD;
}
dp[1-s%2][l][1] = r;
}
for(int l = 0; l < cur; l++){
if(!included[s+1][l]){
dp[1-s%2][l][1] = 0;
}
}
int aa = s % 2;
int bb = 1 - s % 2;
for(int j = 0; j < cur; j++){
for(int k = 1; k <= s+2; k++) if(dp[aa][j][k]) {
dp[bb][j][k] += dp[aa][j][k];
if(dp[bb][j][k] >= MOD) dp[bb][j][k] -= MOD;
if(included[s+1][j]){
dp[bb][j][k+1] += dp[aa][j][k];
if(dp[bb][j][k+1] >= MOD) dp[bb][j][k+1] -= MOD;
}
}
}
}
cout << (dp[1-n%2][cur-1][1]+MOD-1) % MOD << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1095 ms |
30260 KB |
Output is correct |
2 |
Correct |
935 ms |
30280 KB |
Output is correct |
3 |
Correct |
1016 ms |
30264 KB |
Output is correct |
4 |
Correct |
966 ms |
30276 KB |
Output is correct |
5 |
Correct |
847 ms |
30284 KB |
Output is correct |
6 |
Correct |
992 ms |
30284 KB |
Output is correct |
7 |
Correct |
991 ms |
30388 KB |
Output is correct |
8 |
Correct |
1048 ms |
30168 KB |
Output is correct |
9 |
Correct |
907 ms |
30284 KB |
Output is correct |
10 |
Correct |
888 ms |
30272 KB |
Output is correct |
11 |
Correct |
918 ms |
30268 KB |
Output is correct |
12 |
Correct |
910 ms |
30284 KB |
Output is correct |
13 |
Correct |
1002 ms |
30276 KB |
Output is correct |
14 |
Correct |
792 ms |
30276 KB |
Output is correct |
15 |
Correct |
923 ms |
30264 KB |
Output is correct |
16 |
Correct |
551 ms |
22028 KB |
Output is correct |
17 |
Correct |
464 ms |
22220 KB |
Output is correct |
18 |
Correct |
485 ms |
22116 KB |
Output is correct |
19 |
Correct |
532 ms |
22220 KB |
Output is correct |
20 |
Correct |
517 ms |
22212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1095 ms |
30260 KB |
Output is correct |
2 |
Correct |
935 ms |
30280 KB |
Output is correct |
3 |
Correct |
1016 ms |
30264 KB |
Output is correct |
4 |
Correct |
966 ms |
30276 KB |
Output is correct |
5 |
Correct |
847 ms |
30284 KB |
Output is correct |
6 |
Correct |
992 ms |
30284 KB |
Output is correct |
7 |
Correct |
991 ms |
30388 KB |
Output is correct |
8 |
Correct |
1048 ms |
30168 KB |
Output is correct |
9 |
Correct |
907 ms |
30284 KB |
Output is correct |
10 |
Correct |
888 ms |
30272 KB |
Output is correct |
11 |
Correct |
918 ms |
30268 KB |
Output is correct |
12 |
Correct |
910 ms |
30284 KB |
Output is correct |
13 |
Correct |
1002 ms |
30276 KB |
Output is correct |
14 |
Correct |
792 ms |
30276 KB |
Output is correct |
15 |
Correct |
923 ms |
30264 KB |
Output is correct |
16 |
Correct |
551 ms |
22028 KB |
Output is correct |
17 |
Correct |
464 ms |
22220 KB |
Output is correct |
18 |
Correct |
485 ms |
22116 KB |
Output is correct |
19 |
Correct |
532 ms |
22220 KB |
Output is correct |
20 |
Correct |
517 ms |
22212 KB |
Output is correct |
21 |
Correct |
1212 ms |
29560 KB |
Output is correct |
22 |
Correct |
1208 ms |
29684 KB |
Output is correct |
23 |
Correct |
981 ms |
29520 KB |
Output is correct |
24 |
Correct |
1209 ms |
29388 KB |
Output is correct |
25 |
Correct |
1155 ms |
29516 KB |
Output is correct |
26 |
Correct |
1082 ms |
29260 KB |
Output is correct |
27 |
Correct |
1295 ms |
29416 KB |
Output is correct |
28 |
Correct |
1116 ms |
29300 KB |
Output is correct |
29 |
Correct |
1173 ms |
29260 KB |
Output is correct |
30 |
Correct |
983 ms |
30156 KB |
Output is correct |
31 |
Correct |
896 ms |
30284 KB |
Output is correct |
32 |
Correct |
840 ms |
30268 KB |
Output is correct |
33 |
Correct |
945 ms |
30260 KB |
Output is correct |
34 |
Correct |
989 ms |
30208 KB |
Output is correct |
35 |
Correct |
995 ms |
30244 KB |
Output is correct |
36 |
Correct |
887 ms |
30244 KB |
Output is correct |
37 |
Correct |
1010 ms |
30244 KB |
Output is correct |
38 |
Correct |
954 ms |
30228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
20076 KB |
Output is correct |
2 |
Correct |
117 ms |
20004 KB |
Output is correct |
3 |
Correct |
117 ms |
20060 KB |
Output is correct |
4 |
Correct |
154 ms |
20044 KB |
Output is correct |
5 |
Correct |
121 ms |
20060 KB |
Output is correct |
6 |
Correct |
116 ms |
20060 KB |
Output is correct |
7 |
Correct |
115 ms |
20064 KB |
Output is correct |
8 |
Correct |
97 ms |
20060 KB |
Output is correct |
9 |
Correct |
89 ms |
20064 KB |
Output is correct |
10 |
Correct |
107 ms |
20044 KB |
Output is correct |
11 |
Correct |
124 ms |
20016 KB |
Output is correct |
12 |
Correct |
113 ms |
20044 KB |
Output is correct |
13 |
Correct |
125 ms |
20064 KB |
Output is correct |
14 |
Correct |
100 ms |
20168 KB |
Output is correct |
15 |
Correct |
124 ms |
19964 KB |
Output is correct |
16 |
Correct |
129 ms |
19364 KB |
Output is correct |
17 |
Correct |
114 ms |
19276 KB |
Output is correct |
18 |
Correct |
115 ms |
19324 KB |
Output is correct |
19 |
Correct |
89 ms |
19316 KB |
Output is correct |
20 |
Correct |
95 ms |
19276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1095 ms |
30260 KB |
Output is correct |
2 |
Correct |
935 ms |
30280 KB |
Output is correct |
3 |
Correct |
1016 ms |
30264 KB |
Output is correct |
4 |
Correct |
966 ms |
30276 KB |
Output is correct |
5 |
Correct |
847 ms |
30284 KB |
Output is correct |
6 |
Correct |
992 ms |
30284 KB |
Output is correct |
7 |
Correct |
991 ms |
30388 KB |
Output is correct |
8 |
Correct |
1048 ms |
30168 KB |
Output is correct |
9 |
Correct |
907 ms |
30284 KB |
Output is correct |
10 |
Correct |
888 ms |
30272 KB |
Output is correct |
11 |
Correct |
918 ms |
30268 KB |
Output is correct |
12 |
Correct |
910 ms |
30284 KB |
Output is correct |
13 |
Correct |
1002 ms |
30276 KB |
Output is correct |
14 |
Correct |
792 ms |
30276 KB |
Output is correct |
15 |
Correct |
923 ms |
30264 KB |
Output is correct |
16 |
Correct |
551 ms |
22028 KB |
Output is correct |
17 |
Correct |
464 ms |
22220 KB |
Output is correct |
18 |
Correct |
485 ms |
22116 KB |
Output is correct |
19 |
Correct |
532 ms |
22220 KB |
Output is correct |
20 |
Correct |
517 ms |
22212 KB |
Output is correct |
21 |
Correct |
1212 ms |
29560 KB |
Output is correct |
22 |
Correct |
1208 ms |
29684 KB |
Output is correct |
23 |
Correct |
981 ms |
29520 KB |
Output is correct |
24 |
Correct |
1209 ms |
29388 KB |
Output is correct |
25 |
Correct |
1155 ms |
29516 KB |
Output is correct |
26 |
Correct |
1082 ms |
29260 KB |
Output is correct |
27 |
Correct |
1295 ms |
29416 KB |
Output is correct |
28 |
Correct |
1116 ms |
29300 KB |
Output is correct |
29 |
Correct |
1173 ms |
29260 KB |
Output is correct |
30 |
Correct |
983 ms |
30156 KB |
Output is correct |
31 |
Correct |
896 ms |
30284 KB |
Output is correct |
32 |
Correct |
840 ms |
30268 KB |
Output is correct |
33 |
Correct |
945 ms |
30260 KB |
Output is correct |
34 |
Correct |
989 ms |
30208 KB |
Output is correct |
35 |
Correct |
995 ms |
30244 KB |
Output is correct |
36 |
Correct |
887 ms |
30244 KB |
Output is correct |
37 |
Correct |
1010 ms |
30244 KB |
Output is correct |
38 |
Correct |
954 ms |
30228 KB |
Output is correct |
39 |
Correct |
106 ms |
20076 KB |
Output is correct |
40 |
Correct |
117 ms |
20004 KB |
Output is correct |
41 |
Correct |
117 ms |
20060 KB |
Output is correct |
42 |
Correct |
154 ms |
20044 KB |
Output is correct |
43 |
Correct |
121 ms |
20060 KB |
Output is correct |
44 |
Correct |
116 ms |
20060 KB |
Output is correct |
45 |
Correct |
115 ms |
20064 KB |
Output is correct |
46 |
Correct |
97 ms |
20060 KB |
Output is correct |
47 |
Correct |
89 ms |
20064 KB |
Output is correct |
48 |
Correct |
107 ms |
20044 KB |
Output is correct |
49 |
Correct |
124 ms |
20016 KB |
Output is correct |
50 |
Correct |
113 ms |
20044 KB |
Output is correct |
51 |
Correct |
125 ms |
20064 KB |
Output is correct |
52 |
Correct |
100 ms |
20168 KB |
Output is correct |
53 |
Correct |
124 ms |
19964 KB |
Output is correct |
54 |
Correct |
129 ms |
19364 KB |
Output is correct |
55 |
Correct |
114 ms |
19276 KB |
Output is correct |
56 |
Correct |
115 ms |
19324 KB |
Output is correct |
57 |
Correct |
89 ms |
19316 KB |
Output is correct |
58 |
Correct |
95 ms |
19276 KB |
Output is correct |
59 |
Correct |
1318 ms |
30264 KB |
Output is correct |
60 |
Correct |
1242 ms |
30264 KB |
Output is correct |
61 |
Correct |
1098 ms |
30284 KB |
Output is correct |
62 |
Correct |
1372 ms |
30268 KB |
Output is correct |
63 |
Correct |
1110 ms |
30284 KB |
Output is correct |
64 |
Correct |
1337 ms |
30268 KB |
Output is correct |
65 |
Correct |
1423 ms |
30288 KB |
Output is correct |
66 |
Correct |
1269 ms |
30284 KB |
Output is correct |
67 |
Correct |
1234 ms |
30268 KB |
Output is correct |
68 |
Correct |
1279 ms |
30284 KB |
Output is correct |
69 |
Correct |
1258 ms |
30348 KB |
Output is correct |
70 |
Correct |
1138 ms |
30340 KB |
Output is correct |
71 |
Correct |
1369 ms |
30284 KB |
Output is correct |
72 |
Correct |
1258 ms |
30268 KB |
Output is correct |
73 |
Correct |
1392 ms |
30260 KB |
Output is correct |
74 |
Incorrect |
466 ms |
22092 KB |
Output isn't correct |
75 |
Halted |
0 ms |
0 KB |
- |