답안 #46728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46728 2018-04-22T16:04:41 Z Trans Boat (APIO16_boat) C++14
100 / 100
630 ms 4916 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]);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4216 KB Output is correct
2 Correct 11 ms 4324 KB Output is correct
3 Correct 11 ms 4376 KB Output is correct
4 Correct 11 ms 4376 KB Output is correct
5 Correct 11 ms 4428 KB Output is correct
6 Correct 12 ms 4436 KB Output is correct
7 Correct 11 ms 4436 KB Output is correct
8 Correct 12 ms 4452 KB Output is correct
9 Correct 11 ms 4512 KB Output is correct
10 Correct 11 ms 4512 KB Output is correct
11 Correct 11 ms 4584 KB Output is correct
12 Correct 11 ms 4604 KB Output is correct
13 Correct 11 ms 4604 KB Output is correct
14 Correct 11 ms 4604 KB Output is correct
15 Correct 13 ms 4604 KB Output is correct
16 Correct 5 ms 4604 KB Output is correct
17 Correct 5 ms 4604 KB Output is correct
18 Correct 5 ms 4604 KB Output is correct
19 Correct 5 ms 4604 KB Output is correct
20 Correct 5 ms 4604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4216 KB Output is correct
2 Correct 11 ms 4324 KB Output is correct
3 Correct 11 ms 4376 KB Output is correct
4 Correct 11 ms 4376 KB Output is correct
5 Correct 11 ms 4428 KB Output is correct
6 Correct 12 ms 4436 KB Output is correct
7 Correct 11 ms 4436 KB Output is correct
8 Correct 12 ms 4452 KB Output is correct
9 Correct 11 ms 4512 KB Output is correct
10 Correct 11 ms 4512 KB Output is correct
11 Correct 11 ms 4584 KB Output is correct
12 Correct 11 ms 4604 KB Output is correct
13 Correct 11 ms 4604 KB Output is correct
14 Correct 11 ms 4604 KB Output is correct
15 Correct 13 ms 4604 KB Output is correct
16 Correct 5 ms 4604 KB Output is correct
17 Correct 5 ms 4604 KB Output is correct
18 Correct 5 ms 4604 KB Output is correct
19 Correct 5 ms 4604 KB Output is correct
20 Correct 5 ms 4604 KB Output is correct
21 Correct 208 ms 4604 KB Output is correct
22 Correct 200 ms 4604 KB Output is correct
23 Correct 178 ms 4604 KB Output is correct
24 Correct 208 ms 4604 KB Output is correct
25 Correct 214 ms 4604 KB Output is correct
26 Correct 424 ms 4604 KB Output is correct
27 Correct 424 ms 4608 KB Output is correct
28 Correct 438 ms 4608 KB Output is correct
29 Correct 449 ms 4608 KB Output is correct
30 Correct 11 ms 4608 KB Output is correct
31 Correct 11 ms 4608 KB Output is correct
32 Correct 12 ms 4608 KB Output is correct
33 Correct 11 ms 4608 KB Output is correct
34 Correct 12 ms 4608 KB Output is correct
35 Correct 11 ms 4608 KB Output is correct
36 Correct 11 ms 4608 KB Output is correct
37 Correct 11 ms 4608 KB Output is correct
38 Correct 12 ms 4608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4608 KB Output is correct
2 Correct 4 ms 4608 KB Output is correct
3 Correct 4 ms 4608 KB Output is correct
4 Correct 4 ms 4608 KB Output is correct
5 Correct 4 ms 4608 KB Output is correct
6 Correct 7 ms 4608 KB Output is correct
7 Correct 7 ms 4608 KB Output is correct
8 Correct 7 ms 4608 KB Output is correct
9 Correct 7 ms 4608 KB Output is correct
10 Correct 8 ms 4608 KB Output is correct
11 Correct 5 ms 4608 KB Output is correct
12 Correct 4 ms 4608 KB Output is correct
13 Correct 4 ms 4608 KB Output is correct
14 Correct 4 ms 4608 KB Output is correct
15 Correct 4 ms 4608 KB Output is correct
16 Correct 3 ms 4608 KB Output is correct
17 Correct 3 ms 4608 KB Output is correct
18 Correct 3 ms 4608 KB Output is correct
19 Correct 3 ms 4608 KB Output is correct
20 Correct 3 ms 4608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4216 KB Output is correct
2 Correct 11 ms 4324 KB Output is correct
3 Correct 11 ms 4376 KB Output is correct
4 Correct 11 ms 4376 KB Output is correct
5 Correct 11 ms 4428 KB Output is correct
6 Correct 12 ms 4436 KB Output is correct
7 Correct 11 ms 4436 KB Output is correct
8 Correct 12 ms 4452 KB Output is correct
9 Correct 11 ms 4512 KB Output is correct
10 Correct 11 ms 4512 KB Output is correct
11 Correct 11 ms 4584 KB Output is correct
12 Correct 11 ms 4604 KB Output is correct
13 Correct 11 ms 4604 KB Output is correct
14 Correct 11 ms 4604 KB Output is correct
15 Correct 13 ms 4604 KB Output is correct
16 Correct 5 ms 4604 KB Output is correct
17 Correct 5 ms 4604 KB Output is correct
18 Correct 5 ms 4604 KB Output is correct
19 Correct 5 ms 4604 KB Output is correct
20 Correct 5 ms 4604 KB Output is correct
21 Correct 208 ms 4604 KB Output is correct
22 Correct 200 ms 4604 KB Output is correct
23 Correct 178 ms 4604 KB Output is correct
24 Correct 208 ms 4604 KB Output is correct
25 Correct 214 ms 4604 KB Output is correct
26 Correct 424 ms 4604 KB Output is correct
27 Correct 424 ms 4608 KB Output is correct
28 Correct 438 ms 4608 KB Output is correct
29 Correct 449 ms 4608 KB Output is correct
30 Correct 11 ms 4608 KB Output is correct
31 Correct 11 ms 4608 KB Output is correct
32 Correct 12 ms 4608 KB Output is correct
33 Correct 11 ms 4608 KB Output is correct
34 Correct 12 ms 4608 KB Output is correct
35 Correct 11 ms 4608 KB Output is correct
36 Correct 11 ms 4608 KB Output is correct
37 Correct 11 ms 4608 KB Output is correct
38 Correct 12 ms 4608 KB Output is correct
39 Correct 4 ms 4608 KB Output is correct
40 Correct 4 ms 4608 KB Output is correct
41 Correct 4 ms 4608 KB Output is correct
42 Correct 4 ms 4608 KB Output is correct
43 Correct 4 ms 4608 KB Output is correct
44 Correct 7 ms 4608 KB Output is correct
45 Correct 7 ms 4608 KB Output is correct
46 Correct 7 ms 4608 KB Output is correct
47 Correct 7 ms 4608 KB Output is correct
48 Correct 8 ms 4608 KB Output is correct
49 Correct 5 ms 4608 KB Output is correct
50 Correct 4 ms 4608 KB Output is correct
51 Correct 4 ms 4608 KB Output is correct
52 Correct 4 ms 4608 KB Output is correct
53 Correct 4 ms 4608 KB Output is correct
54 Correct 3 ms 4608 KB Output is correct
55 Correct 3 ms 4608 KB Output is correct
56 Correct 3 ms 4608 KB Output is correct
57 Correct 3 ms 4608 KB Output is correct
58 Correct 3 ms 4608 KB Output is correct
59 Correct 268 ms 4608 KB Output is correct
60 Correct 247 ms 4608 KB Output is correct
61 Correct 285 ms 4652 KB Output is correct
62 Correct 290 ms 4808 KB Output is correct
63 Correct 272 ms 4808 KB Output is correct
64 Correct 618 ms 4808 KB Output is correct
65 Correct 629 ms 4808 KB Output is correct
66 Correct 624 ms 4808 KB Output is correct
67 Correct 625 ms 4808 KB Output is correct
68 Correct 630 ms 4808 KB Output is correct
69 Correct 243 ms 4872 KB Output is correct
70 Correct 234 ms 4872 KB Output is correct
71 Correct 233 ms 4872 KB Output is correct
72 Correct 248 ms 4916 KB Output is correct
73 Correct 246 ms 4916 KB Output is correct
74 Correct 36 ms 4916 KB Output is correct
75 Correct 31 ms 4916 KB Output is correct
76 Correct 35 ms 4916 KB Output is correct
77 Correct 32 ms 4916 KB Output is correct
78 Correct 34 ms 4916 KB Output is correct