Submission #113367

# Submission time Handle Problem Language Result Execution time Memory
113367 2019-05-25T08:59:24 Z kajebiii Boat (APIO16_boat) C++17
100 / 100
1808 ms 15792 KB
#include<stdio.h>
#include<algorithm>
 
using namespace std;
 
#define MAXN 555
#define MOD 1000000007
 
long long inv[MAXN+1];
long long iCj[MAXN][MAXN], diCj[2*MAXN-1][MAXN+1];
long long g[MAXN][2*MAXN];
long long dp[MAXN+1][2*MAXN];
 
int main(){
	int N;
	int a[MAXN+1], b[MAXN+1];
	int c[2*MAXN], cn=1;
	int d[2*MAXN];
 
	scanf("%d", &N);
	for(int i=1; i<=N; i++) scanf("%d%d", a+i, b+i);
 
	for(int i=1; i<=N; i++){
		c[i*2-2]=a[i]-1;
		c[i*2-1]=b[i];
	}
	sort(c, c+2*N);
	for(int i=1; i<2*N; i++) if(c[i]!=c[i-1]) c[cn++]=c[i];
	for(int i=1; i<cn; i++) d[i]=c[i]-c[i-1];
 
	for(int i=1; i<=MAXN; i++){
		inv[i]=1;
		long long p=i;
		for(int j=0; (1<<j)<=MOD-2; j++){
			if(((MOD-2)&(1<<j))!=0) inv[i]=inv[i]*p%MOD;
			p=p*p%MOD;
		}
	}
	for(int i=0; i<N; i++) iCj[i][0]=1;
	for(int i=1; i<N; i++) for(int j=1; j<=i; j++) iCj[i][j]=(iCj[i-1][j-1]+iCj[i-1][j])%MOD;
	for(int i=1; i<cn; i++){
		diCj[i][0]=1;
		for(int j=1; j<=d[i]&&j<=N; j++){
			diCj[i][j]=diCj[i][j-1]*(d[i]-j+1)%MOD*inv[j]%MOD;
			//printf("%lld ", diCj[i][j]);
		}
		//printf("\n");
	}
	for(int i=0; i<N; i++) for(int j=1; j<cn; j++){
		g[i][j]=0;
		for(int k=0; k<=i; k++)
			g[i][j]=(g[i][j]+iCj[i][k]*diCj[j][k+1]%MOD)%MOD;
	}
 
	/*
	for(int i=0; i<N; i++){
		for(int j=1; j<cn; j++) printf("%lld ", g[i][j]);
		printf("\n");
	}
	*/
 
	for(int i=0; i<cn; i++) dp[0][i]=1;
	for(int i=1; i<=N; i++) dp[i][0]=1;
	for(int i=1; i<=N; i++) for(int j=1; j<cn; j++){
		dp[i][j]=dp[i][j-1];
		int f=0;
		for(int k=i; k>0; k--) if(a[k]<=c[j-1]+1&&c[j]<=b[k]){
			//printf("%lld{%d} ", dp[i][j], f);
			dp[i][j]=(dp[i][j]+g[f++][j]*dp[k-1][j-1]%MOD)%MOD;
		}
		//printf("(%d %d %lld)\n", i, j, dp[i][j]);
	}
 
	printf("%lld", (dp[N][cn-1]-1+MOD)%MOD);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
boat.cpp:21:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf("%d%d", a+i, b+i);
                          ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 942 ms 15536 KB Output is correct
2 Correct 931 ms 15580 KB Output is correct
3 Correct 960 ms 15344 KB Output is correct
4 Correct 958 ms 15500 KB Output is correct
5 Correct 954 ms 15628 KB Output is correct
6 Correct 756 ms 15408 KB Output is correct
7 Correct 763 ms 15400 KB Output is correct
8 Correct 751 ms 15536 KB Output is correct
9 Correct 781 ms 15608 KB Output is correct
10 Correct 747 ms 15536 KB Output is correct
11 Correct 737 ms 15524 KB Output is correct
12 Correct 735 ms 15452 KB Output is correct
13 Correct 733 ms 15692 KB Output is correct
14 Correct 761 ms 15480 KB Output is correct
15 Correct 779 ms 15372 KB Output is correct
16 Correct 172 ms 8652 KB Output is correct
17 Correct 175 ms 8696 KB Output is correct
18 Correct 174 ms 8696 KB Output is correct
19 Correct 179 ms 8720 KB Output is correct
20 Correct 180 ms 8756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 942 ms 15536 KB Output is correct
2 Correct 931 ms 15580 KB Output is correct
3 Correct 960 ms 15344 KB Output is correct
4 Correct 958 ms 15500 KB Output is correct
5 Correct 954 ms 15628 KB Output is correct
6 Correct 756 ms 15408 KB Output is correct
7 Correct 763 ms 15400 KB Output is correct
8 Correct 751 ms 15536 KB Output is correct
9 Correct 781 ms 15608 KB Output is correct
10 Correct 747 ms 15536 KB Output is correct
11 Correct 737 ms 15524 KB Output is correct
12 Correct 735 ms 15452 KB Output is correct
13 Correct 733 ms 15692 KB Output is correct
14 Correct 761 ms 15480 KB Output is correct
15 Correct 779 ms 15372 KB Output is correct
16 Correct 172 ms 8652 KB Output is correct
17 Correct 175 ms 8696 KB Output is correct
18 Correct 174 ms 8696 KB Output is correct
19 Correct 179 ms 8720 KB Output is correct
20 Correct 180 ms 8756 KB Output is correct
21 Correct 1156 ms 14844 KB Output is correct
22 Correct 1154 ms 15020 KB Output is correct
23 Correct 1395 ms 15016 KB Output is correct
24 Correct 1233 ms 15008 KB Output is correct
25 Correct 1375 ms 14944 KB Output is correct
26 Correct 1256 ms 14812 KB Output is correct
27 Correct 1357 ms 14812 KB Output is correct
28 Correct 1124 ms 14712 KB Output is correct
29 Correct 1117 ms 14888 KB Output is correct
30 Correct 735 ms 15412 KB Output is correct
31 Correct 724 ms 15352 KB Output is correct
32 Correct 727 ms 15368 KB Output is correct
33 Correct 742 ms 15480 KB Output is correct
34 Correct 732 ms 15584 KB Output is correct
35 Correct 986 ms 15608 KB Output is correct
36 Correct 966 ms 15460 KB Output is correct
37 Correct 942 ms 15528 KB Output is correct
38 Correct 944 ms 15608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2816 KB Output is correct
2 Correct 13 ms 2816 KB Output is correct
3 Correct 13 ms 2816 KB Output is correct
4 Correct 13 ms 2688 KB Output is correct
5 Correct 8 ms 2816 KB Output is correct
6 Correct 14 ms 2688 KB Output is correct
7 Correct 17 ms 2808 KB Output is correct
8 Correct 15 ms 2688 KB Output is correct
9 Correct 14 ms 2720 KB Output is correct
10 Correct 14 ms 2816 KB Output is correct
11 Correct 13 ms 2816 KB Output is correct
12 Correct 13 ms 2688 KB Output is correct
13 Correct 13 ms 2688 KB Output is correct
14 Correct 13 ms 2688 KB Output is correct
15 Correct 13 ms 2816 KB Output is correct
16 Correct 9 ms 2304 KB Output is correct
17 Correct 9 ms 2304 KB Output is correct
18 Correct 8 ms 2048 KB Output is correct
19 Correct 9 ms 2176 KB Output is correct
20 Correct 8 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 942 ms 15536 KB Output is correct
2 Correct 931 ms 15580 KB Output is correct
3 Correct 960 ms 15344 KB Output is correct
4 Correct 958 ms 15500 KB Output is correct
5 Correct 954 ms 15628 KB Output is correct
6 Correct 756 ms 15408 KB Output is correct
7 Correct 763 ms 15400 KB Output is correct
8 Correct 751 ms 15536 KB Output is correct
9 Correct 781 ms 15608 KB Output is correct
10 Correct 747 ms 15536 KB Output is correct
11 Correct 737 ms 15524 KB Output is correct
12 Correct 735 ms 15452 KB Output is correct
13 Correct 733 ms 15692 KB Output is correct
14 Correct 761 ms 15480 KB Output is correct
15 Correct 779 ms 15372 KB Output is correct
16 Correct 172 ms 8652 KB Output is correct
17 Correct 175 ms 8696 KB Output is correct
18 Correct 174 ms 8696 KB Output is correct
19 Correct 179 ms 8720 KB Output is correct
20 Correct 180 ms 8756 KB Output is correct
21 Correct 1156 ms 14844 KB Output is correct
22 Correct 1154 ms 15020 KB Output is correct
23 Correct 1395 ms 15016 KB Output is correct
24 Correct 1233 ms 15008 KB Output is correct
25 Correct 1375 ms 14944 KB Output is correct
26 Correct 1256 ms 14812 KB Output is correct
27 Correct 1357 ms 14812 KB Output is correct
28 Correct 1124 ms 14712 KB Output is correct
29 Correct 1117 ms 14888 KB Output is correct
30 Correct 735 ms 15412 KB Output is correct
31 Correct 724 ms 15352 KB Output is correct
32 Correct 727 ms 15368 KB Output is correct
33 Correct 742 ms 15480 KB Output is correct
34 Correct 732 ms 15584 KB Output is correct
35 Correct 986 ms 15608 KB Output is correct
36 Correct 966 ms 15460 KB Output is correct
37 Correct 942 ms 15528 KB Output is correct
38 Correct 944 ms 15608 KB Output is correct
39 Correct 14 ms 2816 KB Output is correct
40 Correct 13 ms 2816 KB Output is correct
41 Correct 13 ms 2816 KB Output is correct
42 Correct 13 ms 2688 KB Output is correct
43 Correct 8 ms 2816 KB Output is correct
44 Correct 14 ms 2688 KB Output is correct
45 Correct 17 ms 2808 KB Output is correct
46 Correct 15 ms 2688 KB Output is correct
47 Correct 14 ms 2720 KB Output is correct
48 Correct 14 ms 2816 KB Output is correct
49 Correct 13 ms 2816 KB Output is correct
50 Correct 13 ms 2688 KB Output is correct
51 Correct 13 ms 2688 KB Output is correct
52 Correct 13 ms 2688 KB Output is correct
53 Correct 13 ms 2816 KB Output is correct
54 Correct 9 ms 2304 KB Output is correct
55 Correct 9 ms 2304 KB Output is correct
56 Correct 8 ms 2048 KB Output is correct
57 Correct 9 ms 2176 KB Output is correct
58 Correct 8 ms 2176 KB Output is correct
59 Correct 1553 ms 15764 KB Output is correct
60 Correct 1611 ms 15708 KB Output is correct
61 Correct 1608 ms 15572 KB Output is correct
62 Correct 1500 ms 15652 KB Output is correct
63 Correct 1639 ms 15552 KB Output is correct
64 Correct 1368 ms 15708 KB Output is correct
65 Correct 1479 ms 15600 KB Output is correct
66 Correct 1304 ms 15696 KB Output is correct
67 Correct 1463 ms 15792 KB Output is correct
68 Correct 1484 ms 15608 KB Output is correct
69 Correct 1808 ms 15744 KB Output is correct
70 Correct 1486 ms 15668 KB Output is correct
71 Correct 1613 ms 15568 KB Output is correct
72 Correct 1266 ms 15648 KB Output is correct
73 Correct 1243 ms 15552 KB Output is correct
74 Correct 232 ms 8696 KB Output is correct
75 Correct 239 ms 8708 KB Output is correct
76 Correct 239 ms 8748 KB Output is correct
77 Correct 237 ms 8664 KB Output is correct
78 Correct 274 ms 8696 KB Output is correct