Submission #202048

# Submission time Handle Problem Language Result Execution time Memory
202048 2020-02-13T09:10:40 Z abil Boat (APIO16_boat) C++14
100 / 100
564 ms 4676 KB
/*
 * Author: Gyeonggeun Kim(kriii)
 * Time Complexity: O(N^3)
 */
#include <stdio.h>
#include <map>
using namespace std;

const long long mod = 1000000007;
int inv[505];

int N,A[505],B[505],L[1005];
long long D[505][1005];

int main()
{
	inv[1] = 1;
	for (int i=2;i<505;i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod;

	scanf ("%d",&N);
	map<int, int> chk;
	for (int i=1;i<=N;i++){
		scanf ("%d %d",&A[i],&B[i]);
		chk[A[i]] = chk[B[i]+1] = 0;
	}

	int c = 0, last = 0;
	for (auto &p : chk){
		L[c] = p.first - last;
		p.second = c++;
		last = p.first;
	}
	c--;

	for (int j=0;j<=c;j++) D[0][j] = 1;
	for (int i=1;i<=N;i++){
		A[i] = chk[A[i]] + 1; B[i] = chk[B[i]+1];
		D[i][0] = 1;
		for (int j=A[i];j<=B[i];j++){
			D[i][j] = (D[i][j] + L[j] * D[i-1][j-1]) % mod;
			long long comb = L[j] - 1; int c = 1;
			for (int k=i-1;k>0;k--){
				if (A[k] <= j && j <= B[k]){
					comb = comb * (L[j] - 1 + c) % mod;
					if (!comb) break;
					comb = comb * inv[++c] % mod;
					D[i][j] = (D[i][j] + comb * D[k-1][j-1]) % mod;
				}
			}
		}
		for (int j=1;j<=c;j++){
			D[i][j] = (D[i][j] + D[i][j-1] + D[i-1][j] - D[i-1][j-1] + mod) % mod;
		}
	}
	
	long long ans = 0;
	printf ("%lld\n",(D[N][c]+mod-1)%mod);

	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:56:12: warning: unused variable 'ans' [-Wunused-variable]
  long long ans = 0;
            ^~~
boat.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d",&N);
  ~~~~~~^~~~~~~~~
boat.cpp:23:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d",&A[i],&B[i]);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4348 KB Output is correct
2 Correct 12 ms 4216 KB Output is correct
3 Correct 13 ms 4344 KB Output is correct
4 Correct 14 ms 4344 KB Output is correct
5 Correct 13 ms 4344 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4216 KB Output is correct
8 Correct 13 ms 4344 KB Output is correct
9 Correct 12 ms 4216 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4344 KB Output is correct
12 Correct 13 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 7 ms 3064 KB Output is correct
17 Correct 8 ms 3064 KB Output is correct
18 Correct 7 ms 3064 KB Output is correct
19 Correct 8 ms 3068 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4348 KB Output is correct
2 Correct 12 ms 4216 KB Output is correct
3 Correct 13 ms 4344 KB Output is correct
4 Correct 14 ms 4344 KB Output is correct
5 Correct 13 ms 4344 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4216 KB Output is correct
8 Correct 13 ms 4344 KB Output is correct
9 Correct 12 ms 4216 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4344 KB Output is correct
12 Correct 13 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 7 ms 3064 KB Output is correct
17 Correct 8 ms 3064 KB Output is correct
18 Correct 7 ms 3064 KB Output is correct
19 Correct 8 ms 3068 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
21 Correct 193 ms 4344 KB Output is correct
22 Correct 177 ms 4344 KB Output is correct
23 Correct 159 ms 4344 KB Output is correct
24 Correct 194 ms 4344 KB Output is correct
25 Correct 184 ms 4344 KB Output is correct
26 Correct 384 ms 4344 KB Output is correct
27 Correct 380 ms 4380 KB Output is correct
28 Correct 398 ms 4344 KB Output is correct
29 Correct 405 ms 4248 KB Output is correct
30 Correct 13 ms 4344 KB Output is correct
31 Correct 15 ms 4344 KB Output is correct
32 Correct 13 ms 4344 KB Output is correct
33 Correct 13 ms 4344 KB Output is correct
34 Correct 13 ms 4344 KB Output is correct
35 Correct 13 ms 4344 KB Output is correct
36 Correct 14 ms 4344 KB Output is correct
37 Correct 13 ms 4344 KB Output is correct
38 Correct 13 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 6 ms 888 KB Output is correct
3 Correct 7 ms 808 KB Output is correct
4 Correct 7 ms 888 KB Output is correct
5 Correct 7 ms 888 KB Output is correct
6 Correct 9 ms 888 KB Output is correct
7 Correct 9 ms 888 KB Output is correct
8 Correct 9 ms 888 KB Output is correct
9 Correct 9 ms 888 KB Output is correct
10 Correct 9 ms 888 KB Output is correct
11 Correct 7 ms 888 KB Output is correct
12 Correct 6 ms 888 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 7 ms 888 KB Output is correct
15 Correct 7 ms 892 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 6 ms 760 KB Output is correct
18 Correct 6 ms 760 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 7 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4348 KB Output is correct
2 Correct 12 ms 4216 KB Output is correct
3 Correct 13 ms 4344 KB Output is correct
4 Correct 14 ms 4344 KB Output is correct
5 Correct 13 ms 4344 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4216 KB Output is correct
8 Correct 13 ms 4344 KB Output is correct
9 Correct 12 ms 4216 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4344 KB Output is correct
12 Correct 13 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 7 ms 3064 KB Output is correct
17 Correct 8 ms 3064 KB Output is correct
18 Correct 7 ms 3064 KB Output is correct
19 Correct 8 ms 3068 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
21 Correct 193 ms 4344 KB Output is correct
22 Correct 177 ms 4344 KB Output is correct
23 Correct 159 ms 4344 KB Output is correct
24 Correct 194 ms 4344 KB Output is correct
25 Correct 184 ms 4344 KB Output is correct
26 Correct 384 ms 4344 KB Output is correct
27 Correct 380 ms 4380 KB Output is correct
28 Correct 398 ms 4344 KB Output is correct
29 Correct 405 ms 4248 KB Output is correct
30 Correct 13 ms 4344 KB Output is correct
31 Correct 15 ms 4344 KB Output is correct
32 Correct 13 ms 4344 KB Output is correct
33 Correct 13 ms 4344 KB Output is correct
34 Correct 13 ms 4344 KB Output is correct
35 Correct 13 ms 4344 KB Output is correct
36 Correct 14 ms 4344 KB Output is correct
37 Correct 13 ms 4344 KB Output is correct
38 Correct 13 ms 4344 KB Output is correct
39 Correct 7 ms 888 KB Output is correct
40 Correct 6 ms 888 KB Output is correct
41 Correct 7 ms 808 KB Output is correct
42 Correct 7 ms 888 KB Output is correct
43 Correct 7 ms 888 KB Output is correct
44 Correct 9 ms 888 KB Output is correct
45 Correct 9 ms 888 KB Output is correct
46 Correct 9 ms 888 KB Output is correct
47 Correct 9 ms 888 KB Output is correct
48 Correct 9 ms 888 KB Output is correct
49 Correct 7 ms 888 KB Output is correct
50 Correct 6 ms 888 KB Output is correct
51 Correct 7 ms 888 KB Output is correct
52 Correct 7 ms 888 KB Output is correct
53 Correct 7 ms 892 KB Output is correct
54 Correct 6 ms 760 KB Output is correct
55 Correct 6 ms 760 KB Output is correct
56 Correct 6 ms 760 KB Output is correct
57 Correct 6 ms 760 KB Output is correct
58 Correct 7 ms 760 KB Output is correct
59 Correct 241 ms 4344 KB Output is correct
60 Correct 220 ms 4348 KB Output is correct
61 Correct 211 ms 4676 KB Output is correct
62 Correct 247 ms 4360 KB Output is correct
63 Correct 227 ms 4344 KB Output is correct
64 Correct 560 ms 4344 KB Output is correct
65 Correct 558 ms 4472 KB Output is correct
66 Correct 557 ms 4344 KB Output is correct
67 Correct 561 ms 4344 KB Output is correct
68 Correct 564 ms 4392 KB Output is correct
69 Correct 209 ms 4344 KB Output is correct
70 Correct 214 ms 4388 KB Output is correct
71 Correct 214 ms 4344 KB Output is correct
72 Correct 224 ms 4344 KB Output is correct
73 Correct 232 ms 4344 KB Output is correct
74 Correct 32 ms 3064 KB Output is correct
75 Correct 30 ms 3064 KB Output is correct
76 Correct 32 ms 3064 KB Output is correct
77 Correct 31 ms 3064 KB Output is correct
78 Correct 33 ms 3064 KB Output is correct