Submission #108406

# Submission time Handle Problem Language Result Execution time Memory
108406 2019-04-29T06:39:54 Z nxteru Boat (APIO16_boat) C++14
58 / 100
2000 ms 12360 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define M 1000000007
#define PB push_back
ll n,a[505],b[505],dp[505][1005],s[1005][505],f[505],ans,r[1005][505];
vector<ll>cm;
int main(void){
    scanf("%lld",&n);
    f[1]=1;
    for(int i=2;i<n;i++)f[i]=M-(M/i)*f[M%i]%M;
    for(int i=0;i<n;i++){
		scanf("%lld%lld",a+i,b+i);
		a[i]--;
		cm.PB(a[i]);
		cm.PB(b[i]);
	}
	sort(cm.begin(),cm.end());
	cm.erase(unique(cm.begin(),cm.end()),cm.end());
	for(int i=0;i<n;i++){
		a[i]=lower_bound(cm.begin(),cm.end(),a[i])-cm.begin();
		b[i]=lower_bound(cm.begin(),cm.end(),b[i])-cm.begin();
	}
	for(int i=n-1;i>=0;i--){
		for(int j=1;j<cm.size();j++){
			if(a[i]<j&&j<=b[i])r[j][i]++;
			r[j][i]+=r[j][i+1];
		}
	}
	for(int i=1;i<cm.size();i++){
		ll p=cm[i]-cm[i-1];
		s[i][0]=1;
		for(ll j=1;j<n;j++){
			s[i][j]=s[i][j-1]*(p+j-1LL)%M*f[j]%M;
		}
	}
	for(int i=0;i<n;i++){
		ll p=1;
		for(int j=1;j<=b[i];j++){
			if(j>a[i]){
				dp[i][j]=p;
				ans=(ans+p*s[j][r[j][i]]%M)%M;
			}
			for(int k=0;k<i;k++)p=(p+dp[k][j]*s[j][r[j][k]-r[j][i]]%M)%M;
		}
	}
	printf("%lld\n",ans);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:25:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=1;j<cm.size();j++){
               ~^~~~~~~~~~
boat.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<cm.size();i++){
              ~^~~~~~~~~~
boat.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
boat.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",a+i,b+i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 777 ms 10332 KB Output is correct
2 Correct 612 ms 10256 KB Output is correct
3 Correct 575 ms 10120 KB Output is correct
4 Correct 590 ms 10204 KB Output is correct
5 Correct 604 ms 10300 KB Output is correct
6 Correct 1091 ms 10432 KB Output is correct
7 Correct 1244 ms 10336 KB Output is correct
8 Correct 1091 ms 10252 KB Output is correct
9 Correct 1073 ms 10360 KB Output is correct
10 Correct 1020 ms 10468 KB Output is correct
11 Correct 1054 ms 10336 KB Output is correct
12 Correct 874 ms 10300 KB Output is correct
13 Correct 1134 ms 10448 KB Output is correct
14 Correct 1043 ms 10348 KB Output is correct
15 Correct 1087 ms 10456 KB Output is correct
16 Correct 70 ms 3832 KB Output is correct
17 Correct 75 ms 3980 KB Output is correct
18 Correct 86 ms 3836 KB Output is correct
19 Correct 104 ms 3992 KB Output is correct
20 Correct 69 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 777 ms 10332 KB Output is correct
2 Correct 612 ms 10256 KB Output is correct
3 Correct 575 ms 10120 KB Output is correct
4 Correct 590 ms 10204 KB Output is correct
5 Correct 604 ms 10300 KB Output is correct
6 Correct 1091 ms 10432 KB Output is correct
7 Correct 1244 ms 10336 KB Output is correct
8 Correct 1091 ms 10252 KB Output is correct
9 Correct 1073 ms 10360 KB Output is correct
10 Correct 1020 ms 10468 KB Output is correct
11 Correct 1054 ms 10336 KB Output is correct
12 Correct 874 ms 10300 KB Output is correct
13 Correct 1134 ms 10448 KB Output is correct
14 Correct 1043 ms 10348 KB Output is correct
15 Correct 1087 ms 10456 KB Output is correct
16 Correct 70 ms 3832 KB Output is correct
17 Correct 75 ms 3980 KB Output is correct
18 Correct 86 ms 3836 KB Output is correct
19 Correct 104 ms 3992 KB Output is correct
20 Correct 69 ms 3832 KB Output is correct
21 Correct 1203 ms 10684 KB Output is correct
22 Correct 1149 ms 10844 KB Output is correct
23 Correct 1093 ms 10640 KB Output is correct
24 Correct 1035 ms 10608 KB Output is correct
25 Correct 846 ms 10744 KB Output is correct
26 Correct 1467 ms 11036 KB Output is correct
27 Correct 1535 ms 11292 KB Output is correct
28 Correct 1200 ms 11108 KB Output is correct
29 Correct 1547 ms 11208 KB Output is correct
30 Correct 663 ms 10392 KB Output is correct
31 Correct 668 ms 10360 KB Output is correct
32 Correct 1010 ms 10488 KB Output is correct
33 Correct 1008 ms 10488 KB Output is correct
34 Correct 1077 ms 10252 KB Output is correct
35 Correct 760 ms 10224 KB Output is correct
36 Correct 708 ms 10312 KB Output is correct
37 Correct 599 ms 10360 KB Output is correct
38 Correct 764 ms 10104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2432 KB Output is correct
2 Correct 8 ms 2428 KB Output is correct
3 Correct 8 ms 2432 KB Output is correct
4 Correct 9 ms 2432 KB Output is correct
5 Correct 8 ms 2304 KB Output is correct
6 Correct 10 ms 2432 KB Output is correct
7 Correct 10 ms 2380 KB Output is correct
8 Correct 15 ms 2432 KB Output is correct
9 Correct 10 ms 2432 KB Output is correct
10 Correct 12 ms 2560 KB Output is correct
11 Correct 11 ms 2432 KB Output is correct
12 Correct 11 ms 2304 KB Output is correct
13 Correct 10 ms 2432 KB Output is correct
14 Correct 8 ms 2432 KB Output is correct
15 Correct 10 ms 2560 KB Output is correct
16 Correct 6 ms 1792 KB Output is correct
17 Correct 7 ms 1664 KB Output is correct
18 Correct 6 ms 1664 KB Output is correct
19 Correct 6 ms 1692 KB Output is correct
20 Correct 5 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 777 ms 10332 KB Output is correct
2 Correct 612 ms 10256 KB Output is correct
3 Correct 575 ms 10120 KB Output is correct
4 Correct 590 ms 10204 KB Output is correct
5 Correct 604 ms 10300 KB Output is correct
6 Correct 1091 ms 10432 KB Output is correct
7 Correct 1244 ms 10336 KB Output is correct
8 Correct 1091 ms 10252 KB Output is correct
9 Correct 1073 ms 10360 KB Output is correct
10 Correct 1020 ms 10468 KB Output is correct
11 Correct 1054 ms 10336 KB Output is correct
12 Correct 874 ms 10300 KB Output is correct
13 Correct 1134 ms 10448 KB Output is correct
14 Correct 1043 ms 10348 KB Output is correct
15 Correct 1087 ms 10456 KB Output is correct
16 Correct 70 ms 3832 KB Output is correct
17 Correct 75 ms 3980 KB Output is correct
18 Correct 86 ms 3836 KB Output is correct
19 Correct 104 ms 3992 KB Output is correct
20 Correct 69 ms 3832 KB Output is correct
21 Correct 1203 ms 10684 KB Output is correct
22 Correct 1149 ms 10844 KB Output is correct
23 Correct 1093 ms 10640 KB Output is correct
24 Correct 1035 ms 10608 KB Output is correct
25 Correct 846 ms 10744 KB Output is correct
26 Correct 1467 ms 11036 KB Output is correct
27 Correct 1535 ms 11292 KB Output is correct
28 Correct 1200 ms 11108 KB Output is correct
29 Correct 1547 ms 11208 KB Output is correct
30 Correct 663 ms 10392 KB Output is correct
31 Correct 668 ms 10360 KB Output is correct
32 Correct 1010 ms 10488 KB Output is correct
33 Correct 1008 ms 10488 KB Output is correct
34 Correct 1077 ms 10252 KB Output is correct
35 Correct 760 ms 10224 KB Output is correct
36 Correct 708 ms 10312 KB Output is correct
37 Correct 599 ms 10360 KB Output is correct
38 Correct 764 ms 10104 KB Output is correct
39 Correct 8 ms 2432 KB Output is correct
40 Correct 8 ms 2428 KB Output is correct
41 Correct 8 ms 2432 KB Output is correct
42 Correct 9 ms 2432 KB Output is correct
43 Correct 8 ms 2304 KB Output is correct
44 Correct 10 ms 2432 KB Output is correct
45 Correct 10 ms 2380 KB Output is correct
46 Correct 15 ms 2432 KB Output is correct
47 Correct 10 ms 2432 KB Output is correct
48 Correct 12 ms 2560 KB Output is correct
49 Correct 11 ms 2432 KB Output is correct
50 Correct 11 ms 2304 KB Output is correct
51 Correct 10 ms 2432 KB Output is correct
52 Correct 8 ms 2432 KB Output is correct
53 Correct 10 ms 2560 KB Output is correct
54 Correct 6 ms 1792 KB Output is correct
55 Correct 7 ms 1664 KB Output is correct
56 Correct 6 ms 1664 KB Output is correct
57 Correct 6 ms 1692 KB Output is correct
58 Correct 5 ms 1664 KB Output is correct
59 Correct 1343 ms 11456 KB Output is correct
60 Correct 1310 ms 11252 KB Output is correct
61 Correct 1162 ms 11280 KB Output is correct
62 Correct 1416 ms 11528 KB Output is correct
63 Correct 1107 ms 11512 KB Output is correct
64 Correct 1759 ms 12356 KB Output is correct
65 Execution timed out 2062 ms 12360 KB Time limit exceeded
66 Halted 0 ms 0 KB -