Submission #99945

# Submission time Handle Problem Language Result Execution time Memory
99945 2019-03-08T21:14:44 Z TadijaSebez Boat (APIO16_boat) C++11
100 / 100
1339 ms 1532 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=505;
const int M=2*N;
const int K=1000050;
const int mod=1e9+7;
int mul(int x, int y){ return (ll)x*y%mod;}
int add(int x, int y){ x+=y;return x>=mod?x-mod:x;}
int sub(int x, int y){ x-=y;return x<0?x+mod:x;}
int pow(int x, int k){ int ans=1;for(;k;k>>=1,x=mul(x,x)) if(k&1) ans=mul(ans,x);return ans;}
int inv(int x){ return pow(x,mod-2);}
int F[K],I[K];
int binom(int n, int k){ return n<k?0:mul(F[n],mul(I[k],I[n-k]));}
int dp[N],tmp[N][N],l[N],r[N];
void calc()
{
	F[0]=1;for(int i=1;i<K;i++) F[i]=mul(F[i-1],i);
	I[K-1]=inv(F[K-1]);for(int i=K-2;~i;i--) I[i]=mul(I[i+1],i+1);
}
int bc[N];
int main()
{
	//calc();
	int n;
	scanf("%i",&n);
	vector<int> all;
	for(int i=1;i<=n;i++)
	{
		scanf("%i %i",&l[i],&r[i]);
		all.pb(l[i]);
		all.pb(r[i]+1);
	}
	sort(all.begin(),all.end());
	all.resize(unique(all.begin(),all.end())-all.begin());
	dp[0]=1;
	for(int t=1;t<all.size();t++)
	{
		int L=all[t]-all[t-1];
		bc[0]=1;
		for(int i=1;i<=n;i++) bc[i]=mul(bc[i-1],mul(L-i+1,inv(i)));
		for(int i=1;i<=n;i++) dp[i]=add(dp[i],dp[i-1]);
		for(int j=1;j<=n;j++)
		{
			for(int i=j;i<=n;i++)
			{
				if(all[t-1]<=r[i] && all[t-1]>=l[i]) tmp[i][j]=j==1?dp[i-1]:tmp[i-1][j-1];
				else tmp[i][j]=0;
			}
			if(j==1) for(int i=n;i>=1;i--) dp[i]=sub(dp[i],dp[i-1]);
			for(int i=j;i<=n;i++) dp[i]=add(dp[i],mul(tmp[i][j],bc[j]));
			for(int i=j;i<=n;i++) tmp[i][j]=add(tmp[i][j],tmp[i-1][j]);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++) ans=add(ans,dp[i]);
	printf("%i\n",ans);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int t=1;t<all.size();t++)
              ~^~~~~~~~~~~
boat.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
boat.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&l[i],&r[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1198 ms 1408 KB Output is correct
2 Correct 1165 ms 1280 KB Output is correct
3 Correct 1174 ms 1400 KB Output is correct
4 Correct 1202 ms 1280 KB Output is correct
5 Correct 1267 ms 1408 KB Output is correct
6 Correct 1221 ms 1408 KB Output is correct
7 Correct 1223 ms 1400 KB Output is correct
8 Correct 1339 ms 1408 KB Output is correct
9 Correct 1237 ms 1280 KB Output is correct
10 Correct 1282 ms 1528 KB Output is correct
11 Correct 1160 ms 1368 KB Output is correct
12 Correct 1242 ms 1400 KB Output is correct
13 Correct 1212 ms 1400 KB Output is correct
14 Correct 1203 ms 1364 KB Output is correct
15 Correct 1153 ms 1400 KB Output is correct
16 Correct 205 ms 1280 KB Output is correct
17 Correct 239 ms 1280 KB Output is correct
18 Correct 208 ms 1280 KB Output is correct
19 Correct 223 ms 1408 KB Output is correct
20 Correct 238 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1198 ms 1408 KB Output is correct
2 Correct 1165 ms 1280 KB Output is correct
3 Correct 1174 ms 1400 KB Output is correct
4 Correct 1202 ms 1280 KB Output is correct
5 Correct 1267 ms 1408 KB Output is correct
6 Correct 1221 ms 1408 KB Output is correct
7 Correct 1223 ms 1400 KB Output is correct
8 Correct 1339 ms 1408 KB Output is correct
9 Correct 1237 ms 1280 KB Output is correct
10 Correct 1282 ms 1528 KB Output is correct
11 Correct 1160 ms 1368 KB Output is correct
12 Correct 1242 ms 1400 KB Output is correct
13 Correct 1212 ms 1400 KB Output is correct
14 Correct 1203 ms 1364 KB Output is correct
15 Correct 1153 ms 1400 KB Output is correct
16 Correct 205 ms 1280 KB Output is correct
17 Correct 239 ms 1280 KB Output is correct
18 Correct 208 ms 1280 KB Output is correct
19 Correct 223 ms 1408 KB Output is correct
20 Correct 238 ms 1408 KB Output is correct
21 Correct 1012 ms 1280 KB Output is correct
22 Correct 1106 ms 1400 KB Output is correct
23 Correct 1229 ms 1400 KB Output is correct
24 Correct 1093 ms 1400 KB Output is correct
25 Correct 1028 ms 1400 KB Output is correct
26 Correct 1029 ms 1280 KB Output is correct
27 Correct 1121 ms 1532 KB Output is correct
28 Correct 1033 ms 1400 KB Output is correct
29 Correct 1061 ms 1268 KB Output is correct
30 Correct 1144 ms 1280 KB Output is correct
31 Correct 1115 ms 1384 KB Output is correct
32 Correct 1131 ms 1420 KB Output is correct
33 Correct 1163 ms 1528 KB Output is correct
34 Correct 1117 ms 1280 KB Output is correct
35 Correct 1202 ms 1388 KB Output is correct
36 Correct 1147 ms 1400 KB Output is correct
37 Correct 1299 ms 1400 KB Output is correct
38 Correct 1208 ms 1384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 512 KB Output is correct
2 Correct 13 ms 512 KB Output is correct
3 Correct 13 ms 512 KB Output is correct
4 Correct 14 ms 512 KB Output is correct
5 Correct 14 ms 512 KB Output is correct
6 Correct 14 ms 512 KB Output is correct
7 Correct 13 ms 512 KB Output is correct
8 Correct 14 ms 512 KB Output is correct
9 Correct 14 ms 512 KB Output is correct
10 Correct 15 ms 512 KB Output is correct
11 Correct 13 ms 512 KB Output is correct
12 Correct 13 ms 512 KB Output is correct
13 Correct 13 ms 512 KB Output is correct
14 Correct 13 ms 512 KB Output is correct
15 Correct 14 ms 512 KB Output is correct
16 Correct 9 ms 512 KB Output is correct
17 Correct 9 ms 512 KB Output is correct
18 Correct 8 ms 512 KB Output is correct
19 Correct 9 ms 512 KB Output is correct
20 Correct 11 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1198 ms 1408 KB Output is correct
2 Correct 1165 ms 1280 KB Output is correct
3 Correct 1174 ms 1400 KB Output is correct
4 Correct 1202 ms 1280 KB Output is correct
5 Correct 1267 ms 1408 KB Output is correct
6 Correct 1221 ms 1408 KB Output is correct
7 Correct 1223 ms 1400 KB Output is correct
8 Correct 1339 ms 1408 KB Output is correct
9 Correct 1237 ms 1280 KB Output is correct
10 Correct 1282 ms 1528 KB Output is correct
11 Correct 1160 ms 1368 KB Output is correct
12 Correct 1242 ms 1400 KB Output is correct
13 Correct 1212 ms 1400 KB Output is correct
14 Correct 1203 ms 1364 KB Output is correct
15 Correct 1153 ms 1400 KB Output is correct
16 Correct 205 ms 1280 KB Output is correct
17 Correct 239 ms 1280 KB Output is correct
18 Correct 208 ms 1280 KB Output is correct
19 Correct 223 ms 1408 KB Output is correct
20 Correct 238 ms 1408 KB Output is correct
21 Correct 1012 ms 1280 KB Output is correct
22 Correct 1106 ms 1400 KB Output is correct
23 Correct 1229 ms 1400 KB Output is correct
24 Correct 1093 ms 1400 KB Output is correct
25 Correct 1028 ms 1400 KB Output is correct
26 Correct 1029 ms 1280 KB Output is correct
27 Correct 1121 ms 1532 KB Output is correct
28 Correct 1033 ms 1400 KB Output is correct
29 Correct 1061 ms 1268 KB Output is correct
30 Correct 1144 ms 1280 KB Output is correct
31 Correct 1115 ms 1384 KB Output is correct
32 Correct 1131 ms 1420 KB Output is correct
33 Correct 1163 ms 1528 KB Output is correct
34 Correct 1117 ms 1280 KB Output is correct
35 Correct 1202 ms 1388 KB Output is correct
36 Correct 1147 ms 1400 KB Output is correct
37 Correct 1299 ms 1400 KB Output is correct
38 Correct 1208 ms 1384 KB Output is correct
39 Correct 13 ms 512 KB Output is correct
40 Correct 13 ms 512 KB Output is correct
41 Correct 13 ms 512 KB Output is correct
42 Correct 14 ms 512 KB Output is correct
43 Correct 14 ms 512 KB Output is correct
44 Correct 14 ms 512 KB Output is correct
45 Correct 13 ms 512 KB Output is correct
46 Correct 14 ms 512 KB Output is correct
47 Correct 14 ms 512 KB Output is correct
48 Correct 15 ms 512 KB Output is correct
49 Correct 13 ms 512 KB Output is correct
50 Correct 13 ms 512 KB Output is correct
51 Correct 13 ms 512 KB Output is correct
52 Correct 13 ms 512 KB Output is correct
53 Correct 14 ms 512 KB Output is correct
54 Correct 9 ms 512 KB Output is correct
55 Correct 9 ms 512 KB Output is correct
56 Correct 8 ms 512 KB Output is correct
57 Correct 9 ms 512 KB Output is correct
58 Correct 11 ms 512 KB Output is correct
59 Correct 1180 ms 1408 KB Output is correct
60 Correct 1165 ms 1400 KB Output is correct
61 Correct 1214 ms 1400 KB Output is correct
62 Correct 1151 ms 1400 KB Output is correct
63 Correct 1224 ms 1500 KB Output is correct
64 Correct 1176 ms 1280 KB Output is correct
65 Correct 1179 ms 1408 KB Output is correct
66 Correct 1182 ms 1408 KB Output is correct
67 Correct 1111 ms 1400 KB Output is correct
68 Correct 1158 ms 1400 KB Output is correct
69 Correct 1265 ms 1528 KB Output is correct
70 Correct 1135 ms 1400 KB Output is correct
71 Correct 1141 ms 1408 KB Output is correct
72 Correct 1157 ms 1420 KB Output is correct
73 Correct 1336 ms 1484 KB Output is correct
74 Correct 221 ms 1280 KB Output is correct
75 Correct 218 ms 1400 KB Output is correct
76 Correct 217 ms 1528 KB Output is correct
77 Correct 255 ms 1408 KB Output is correct
78 Correct 221 ms 1280 KB Output is correct