# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
153029 |
2019-09-11T14:00:47 Z |
arnold518 |
Boat (APIO16_boat) |
C++14 |
|
1127 ms |
11552 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
const ll MOD = 1e9+7;
int N, S, A[MAXN+10], B[MAXN+10];
vector<int> comp;
ll inv[MAXN+10], bino[MAXN+10][MAXN+10], comb[MAXN+10], f[MAXN+10];
ll dp[MAXN+10][MAXN+10], ans;
int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin(); }
ll mypow(ll x, ll y)
{
if(y==0) return 1;
if(y%2) return mypow(x, y-1)*x%MOD;
ll t=mypow(x, y/2);
return t*t%MOD;
}
int main()
{
int i, j, k;
bino[0][0]=1;
for(i=1; i<=MAXN; i++) for(j=0; j<=i; j++)
{
if(j==0 || j==i) bino[i][j]=1;
else bino[i][j]=(bino[i-1][j]+bino[i-1][j-1])%MOD;
}
inv[0]=1;
for(i=1; i<=MAXN; i++) inv[i]=mypow(i, MOD-2);
scanf("%d", &N);
for(i=1; i<=N; i++)
{
scanf("%d%d", &A[i], &B[i]); B[i]++;
comp.push_back(A[i]);
comp.push_back(B[i]);
}
comp.push_back(0);
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
S=comp.size()-2;
ll a=comp[2]-comp[1];
memset(comb, 0, sizeof(comb)); memset(f, 0, sizeof(f));
comb[0]=1;
for(j=1; j<=min(600ll, a); j++) comb[j]=comb[j-1]*(a-j+1)%MOD*inv[j]%MOD;
for(j=1; j<=N; j++)
{
for(k=1; k<=j; k++)
{
f[j]+=comb[k]*bino[j-1][k-1]%MOD;
f[j]%=MOD;
}
}
int cnt=0;
for(i=1; i<=N; i++)
{
if(!(A[i]<=comp[1] && comp[1]<B[i])) continue;
cnt++;
dp[i][1]=f[cnt];
}
dp[0][1]=1;
for(i=2; i<=S; i++)
{
dp[0][i]=1;
a=comp[i+1]-comp[i];
memset(comb, 0, sizeof(comb)); memset(f, 0, sizeof(f));
comb[0]=1;
for(j=1; j<=min(600ll, a); j++) comb[j]=comb[j-1]*(a-j+1)%MOD*inv[j]%MOD;
for(j=1; j<=N; j++)
{
for(k=1; k<=j; k++)
{
f[j]+=comb[k]*bino[j-1][k-1]%MOD;
f[j]%=MOD;
}
}
for(j=1; j<=N; j++)
{
if(!(A[j]<=comp[i] && comp[i]<B[j])) { dp[j][i]=dp[j][i-1]; continue; }
int cnt=1;
for(k=j-1; k>=0; k--)
{
dp[j][i]+=f[cnt]*dp[k][i-1]%MOD;
dp[j][i]%=MOD;
if(A[k]<=comp[i] && comp[i]<B[k]) cnt++;
}
dp[j][i]+=dp[j][i-1]; dp[j][i]%=MOD;
}
}
//for(i=1; i<=N; i++) { for(j=1; j<=S; j++) printf("%lld ", dp[i][j]-dp[i][j-1]); printf("\n"); }
for(i=1; i<=N; i++) ans+=dp[i][S], ans%=MOD;
printf("%lld", ans);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
boat.cpp:43: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]); B[i]++;
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
761 ms |
11228 KB |
Output is correct |
2 |
Correct |
728 ms |
11384 KB |
Output is correct |
3 |
Correct |
727 ms |
11440 KB |
Output is correct |
4 |
Correct |
730 ms |
11504 KB |
Output is correct |
5 |
Correct |
732 ms |
11484 KB |
Output is correct |
6 |
Correct |
727 ms |
11372 KB |
Output is correct |
7 |
Correct |
729 ms |
11440 KB |
Output is correct |
8 |
Correct |
739 ms |
11388 KB |
Output is correct |
9 |
Correct |
729 ms |
11300 KB |
Output is correct |
10 |
Correct |
751 ms |
11308 KB |
Output is correct |
11 |
Correct |
744 ms |
11408 KB |
Output is correct |
12 |
Correct |
737 ms |
11428 KB |
Output is correct |
13 |
Correct |
728 ms |
11300 KB |
Output is correct |
14 |
Correct |
727 ms |
11312 KB |
Output is correct |
15 |
Correct |
730 ms |
11324 KB |
Output is correct |
16 |
Correct |
139 ms |
10016 KB |
Output is correct |
17 |
Correct |
148 ms |
9980 KB |
Output is correct |
18 |
Correct |
143 ms |
9976 KB |
Output is correct |
19 |
Correct |
148 ms |
9976 KB |
Output is correct |
20 |
Correct |
143 ms |
9976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
761 ms |
11228 KB |
Output is correct |
2 |
Correct |
728 ms |
11384 KB |
Output is correct |
3 |
Correct |
727 ms |
11440 KB |
Output is correct |
4 |
Correct |
730 ms |
11504 KB |
Output is correct |
5 |
Correct |
732 ms |
11484 KB |
Output is correct |
6 |
Correct |
727 ms |
11372 KB |
Output is correct |
7 |
Correct |
729 ms |
11440 KB |
Output is correct |
8 |
Correct |
739 ms |
11388 KB |
Output is correct |
9 |
Correct |
729 ms |
11300 KB |
Output is correct |
10 |
Correct |
751 ms |
11308 KB |
Output is correct |
11 |
Correct |
744 ms |
11408 KB |
Output is correct |
12 |
Correct |
737 ms |
11428 KB |
Output is correct |
13 |
Correct |
728 ms |
11300 KB |
Output is correct |
14 |
Correct |
727 ms |
11312 KB |
Output is correct |
15 |
Correct |
730 ms |
11324 KB |
Output is correct |
16 |
Correct |
139 ms |
10016 KB |
Output is correct |
17 |
Correct |
148 ms |
9980 KB |
Output is correct |
18 |
Correct |
143 ms |
9976 KB |
Output is correct |
19 |
Correct |
148 ms |
9976 KB |
Output is correct |
20 |
Correct |
143 ms |
9976 KB |
Output is correct |
21 |
Correct |
899 ms |
11320 KB |
Output is correct |
22 |
Correct |
898 ms |
11284 KB |
Output is correct |
23 |
Correct |
886 ms |
11316 KB |
Output is correct |
24 |
Correct |
878 ms |
11328 KB |
Output is correct |
25 |
Correct |
882 ms |
11412 KB |
Output is correct |
26 |
Correct |
968 ms |
11344 KB |
Output is correct |
27 |
Correct |
995 ms |
11480 KB |
Output is correct |
28 |
Correct |
982 ms |
11312 KB |
Output is correct |
29 |
Correct |
970 ms |
11332 KB |
Output is correct |
30 |
Correct |
740 ms |
11236 KB |
Output is correct |
31 |
Correct |
730 ms |
11316 KB |
Output is correct |
32 |
Correct |
729 ms |
11316 KB |
Output is correct |
33 |
Correct |
731 ms |
11316 KB |
Output is correct |
34 |
Correct |
734 ms |
11336 KB |
Output is correct |
35 |
Correct |
732 ms |
11368 KB |
Output is correct |
36 |
Correct |
729 ms |
11332 KB |
Output is correct |
37 |
Correct |
729 ms |
11320 KB |
Output is correct |
38 |
Correct |
726 ms |
11316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
7904 KB |
Output is correct |
2 |
Correct |
18 ms |
7804 KB |
Output is correct |
3 |
Correct |
19 ms |
7900 KB |
Output is correct |
4 |
Correct |
19 ms |
7800 KB |
Output is correct |
5 |
Correct |
19 ms |
7800 KB |
Output is correct |
6 |
Correct |
20 ms |
7800 KB |
Output is correct |
7 |
Correct |
20 ms |
7800 KB |
Output is correct |
8 |
Correct |
20 ms |
7800 KB |
Output is correct |
9 |
Correct |
20 ms |
7928 KB |
Output is correct |
10 |
Correct |
20 ms |
7924 KB |
Output is correct |
11 |
Correct |
19 ms |
7928 KB |
Output is correct |
12 |
Correct |
22 ms |
7800 KB |
Output is correct |
13 |
Correct |
18 ms |
7800 KB |
Output is correct |
14 |
Correct |
19 ms |
7800 KB |
Output is correct |
15 |
Correct |
19 ms |
7800 KB |
Output is correct |
16 |
Correct |
15 ms |
7772 KB |
Output is correct |
17 |
Correct |
14 ms |
7800 KB |
Output is correct |
18 |
Correct |
15 ms |
7800 KB |
Output is correct |
19 |
Correct |
15 ms |
7928 KB |
Output is correct |
20 |
Correct |
15 ms |
7800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
761 ms |
11228 KB |
Output is correct |
2 |
Correct |
728 ms |
11384 KB |
Output is correct |
3 |
Correct |
727 ms |
11440 KB |
Output is correct |
4 |
Correct |
730 ms |
11504 KB |
Output is correct |
5 |
Correct |
732 ms |
11484 KB |
Output is correct |
6 |
Correct |
727 ms |
11372 KB |
Output is correct |
7 |
Correct |
729 ms |
11440 KB |
Output is correct |
8 |
Correct |
739 ms |
11388 KB |
Output is correct |
9 |
Correct |
729 ms |
11300 KB |
Output is correct |
10 |
Correct |
751 ms |
11308 KB |
Output is correct |
11 |
Correct |
744 ms |
11408 KB |
Output is correct |
12 |
Correct |
737 ms |
11428 KB |
Output is correct |
13 |
Correct |
728 ms |
11300 KB |
Output is correct |
14 |
Correct |
727 ms |
11312 KB |
Output is correct |
15 |
Correct |
730 ms |
11324 KB |
Output is correct |
16 |
Correct |
139 ms |
10016 KB |
Output is correct |
17 |
Correct |
148 ms |
9980 KB |
Output is correct |
18 |
Correct |
143 ms |
9976 KB |
Output is correct |
19 |
Correct |
148 ms |
9976 KB |
Output is correct |
20 |
Correct |
143 ms |
9976 KB |
Output is correct |
21 |
Correct |
899 ms |
11320 KB |
Output is correct |
22 |
Correct |
898 ms |
11284 KB |
Output is correct |
23 |
Correct |
886 ms |
11316 KB |
Output is correct |
24 |
Correct |
878 ms |
11328 KB |
Output is correct |
25 |
Correct |
882 ms |
11412 KB |
Output is correct |
26 |
Correct |
968 ms |
11344 KB |
Output is correct |
27 |
Correct |
995 ms |
11480 KB |
Output is correct |
28 |
Correct |
982 ms |
11312 KB |
Output is correct |
29 |
Correct |
970 ms |
11332 KB |
Output is correct |
30 |
Correct |
740 ms |
11236 KB |
Output is correct |
31 |
Correct |
730 ms |
11316 KB |
Output is correct |
32 |
Correct |
729 ms |
11316 KB |
Output is correct |
33 |
Correct |
731 ms |
11316 KB |
Output is correct |
34 |
Correct |
734 ms |
11336 KB |
Output is correct |
35 |
Correct |
732 ms |
11368 KB |
Output is correct |
36 |
Correct |
729 ms |
11332 KB |
Output is correct |
37 |
Correct |
729 ms |
11320 KB |
Output is correct |
38 |
Correct |
726 ms |
11316 KB |
Output is correct |
39 |
Correct |
19 ms |
7904 KB |
Output is correct |
40 |
Correct |
18 ms |
7804 KB |
Output is correct |
41 |
Correct |
19 ms |
7900 KB |
Output is correct |
42 |
Correct |
19 ms |
7800 KB |
Output is correct |
43 |
Correct |
19 ms |
7800 KB |
Output is correct |
44 |
Correct |
20 ms |
7800 KB |
Output is correct |
45 |
Correct |
20 ms |
7800 KB |
Output is correct |
46 |
Correct |
20 ms |
7800 KB |
Output is correct |
47 |
Correct |
20 ms |
7928 KB |
Output is correct |
48 |
Correct |
20 ms |
7924 KB |
Output is correct |
49 |
Correct |
19 ms |
7928 KB |
Output is correct |
50 |
Correct |
22 ms |
7800 KB |
Output is correct |
51 |
Correct |
18 ms |
7800 KB |
Output is correct |
52 |
Correct |
19 ms |
7800 KB |
Output is correct |
53 |
Correct |
19 ms |
7800 KB |
Output is correct |
54 |
Correct |
15 ms |
7772 KB |
Output is correct |
55 |
Correct |
14 ms |
7800 KB |
Output is correct |
56 |
Correct |
15 ms |
7800 KB |
Output is correct |
57 |
Correct |
15 ms |
7928 KB |
Output is correct |
58 |
Correct |
15 ms |
7800 KB |
Output is correct |
59 |
Correct |
987 ms |
11324 KB |
Output is correct |
60 |
Correct |
982 ms |
11324 KB |
Output is correct |
61 |
Correct |
962 ms |
11372 KB |
Output is correct |
62 |
Correct |
982 ms |
11320 KB |
Output is correct |
63 |
Correct |
981 ms |
11376 KB |
Output is correct |
64 |
Correct |
1118 ms |
11312 KB |
Output is correct |
65 |
Correct |
1109 ms |
11312 KB |
Output is correct |
66 |
Correct |
1108 ms |
11484 KB |
Output is correct |
67 |
Correct |
1111 ms |
11320 KB |
Output is correct |
68 |
Correct |
1127 ms |
11456 KB |
Output is correct |
69 |
Correct |
926 ms |
11320 KB |
Output is correct |
70 |
Correct |
932 ms |
11420 KB |
Output is correct |
71 |
Correct |
925 ms |
11352 KB |
Output is correct |
72 |
Correct |
941 ms |
11552 KB |
Output is correct |
73 |
Correct |
934 ms |
11332 KB |
Output is correct |
74 |
Correct |
193 ms |
10120 KB |
Output is correct |
75 |
Correct |
192 ms |
10012 KB |
Output is correct |
76 |
Correct |
192 ms |
10084 KB |
Output is correct |
77 |
Correct |
191 ms |
10068 KB |
Output is correct |
78 |
Correct |
197 ms |
10032 KB |
Output is correct |