답안 #261922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261922 2020-08-12T07:55:15 Z Saboon Boat (APIO16_boat) C++14
100 / 100
1851 ms 5644 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500 + 10;
const int mod = 1e9 + 7;

int a[maxn], b[maxn];
int dp[maxn][2*maxn], pd[2*maxn][maxn], c[maxn][maxn];
int revpw[maxn];

int power(int a, int b){
	if (b == 0)
		return 1;
	int ret = power(a,b/2);
	ret = 1LL*ret*ret%mod;
	if (b & 1)
		ret = 1LL*ret*a%mod;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> cmp;
	for (int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		b[i] ++;
		cmp.push_back(a[i]);
		cmp.push_back(b[i]);
	}
	sort(cmp.begin(), cmp.end());
	cmp.resize(unique(cmp.begin(),cmp.end())-cmp.begin());
	for (int i = 1; i <= n; i++){
		a[i] = lower_bound(cmp.begin(),cmp.end(),a[i]) - cmp.begin() + 1;
		b[i] = lower_bound(cmp.begin(),cmp.end(),b[i]) - cmp.begin() + 1;
	}
	c[0][0] = 1;
	for (int N = 1; N <= n; N++){
		c[N][0] = 1;
		for (int R = 1; R <= N; R++)
			c[N][R] = (c[N-1][R]+c[N-1][R-1]) % mod;
	}
	for (int i = 1; i <= 500; i++)
		revpw[i] = power(i, mod-2);

	for (int i = 1; i < cmp.size(); i++){
		int m = cmp[i]-cmp[i-1];
		if (m == 1){
			pd[i][1] = 1;
			continue;
		}
		pd[i][1] = m;
		for (int j = 2; j <= n; j++){
			int Cmk = m;
			for (int k = 2; k <= min(m,j); k++){
				Cmk = 1LL*Cmk*revpw[k]%mod*(m-k+1)%mod;
				pd[i][j] = (pd[i][j] + 1LL*c[j-2][k-2]*Cmk) % mod;
			}
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i < cmp.size(); i++)
		dp[0][i] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = a[i]; j < b[i]; j++){
			int cnt = 0;
			for (int k = i-1; k >= 0; k--)
				if (a[k+1] <= j and j < b[k+1])
					dp[i][j] = (dp[i][j] + 1LL*pd[j][++cnt]*dp[k][j-1]) % mod;
		}
		for (int j = a[i]; j < cmp.size(); j++)
			dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
		for (int j = 0; j < cmp.size(); j++)
			dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
	}
	cout << (dp[n][cmp.size()-1]+mod-1) % mod << endl;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < cmp.size(); i++){
                  ~~^~~~~~~~~~~~
boat.cpp:63:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < cmp.size(); i++)
                  ~~^~~~~~~~~~~~
boat.cpp:72:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = a[i]; j < cmp.size(); j++)
                      ~~^~~~~~~~~~~~
boat.cpp:74:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < cmp.size(); j++)
                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 755 ms 5384 KB Output is correct
2 Correct 752 ms 5392 KB Output is correct
3 Correct 765 ms 5444 KB Output is correct
4 Correct 779 ms 5368 KB Output is correct
5 Correct 755 ms 5416 KB Output is correct
6 Correct 741 ms 5368 KB Output is correct
7 Correct 744 ms 5556 KB Output is correct
8 Correct 743 ms 5384 KB Output is correct
9 Correct 774 ms 5416 KB Output is correct
10 Correct 752 ms 5368 KB Output is correct
11 Correct 771 ms 5396 KB Output is correct
12 Correct 778 ms 5428 KB Output is correct
13 Correct 754 ms 5372 KB Output is correct
14 Correct 780 ms 5496 KB Output is correct
15 Correct 779 ms 5456 KB Output is correct
16 Correct 132 ms 3756 KB Output is correct
17 Correct 144 ms 3704 KB Output is correct
18 Correct 139 ms 3676 KB Output is correct
19 Correct 144 ms 3704 KB Output is correct
20 Correct 144 ms 3880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 755 ms 5384 KB Output is correct
2 Correct 752 ms 5392 KB Output is correct
3 Correct 765 ms 5444 KB Output is correct
4 Correct 779 ms 5368 KB Output is correct
5 Correct 755 ms 5416 KB Output is correct
6 Correct 741 ms 5368 KB Output is correct
7 Correct 744 ms 5556 KB Output is correct
8 Correct 743 ms 5384 KB Output is correct
9 Correct 774 ms 5416 KB Output is correct
10 Correct 752 ms 5368 KB Output is correct
11 Correct 771 ms 5396 KB Output is correct
12 Correct 778 ms 5428 KB Output is correct
13 Correct 754 ms 5372 KB Output is correct
14 Correct 780 ms 5496 KB Output is correct
15 Correct 779 ms 5456 KB Output is correct
16 Correct 132 ms 3756 KB Output is correct
17 Correct 144 ms 3704 KB Output is correct
18 Correct 139 ms 3676 KB Output is correct
19 Correct 144 ms 3704 KB Output is correct
20 Correct 144 ms 3880 KB Output is correct
21 Correct 177 ms 5244 KB Output is correct
22 Correct 175 ms 5240 KB Output is correct
23 Correct 157 ms 5112 KB Output is correct
24 Correct 172 ms 5240 KB Output is correct
25 Correct 183 ms 5112 KB Output is correct
26 Correct 326 ms 5112 KB Output is correct
27 Correct 340 ms 5140 KB Output is correct
28 Correct 330 ms 5152 KB Output is correct
29 Correct 324 ms 5244 KB Output is correct
30 Correct 706 ms 5404 KB Output is correct
31 Correct 706 ms 5288 KB Output is correct
32 Correct 713 ms 5496 KB Output is correct
33 Correct 717 ms 5496 KB Output is correct
34 Correct 716 ms 5372 KB Output is correct
35 Correct 701 ms 5412 KB Output is correct
36 Correct 709 ms 5532 KB Output is correct
37 Correct 724 ms 5404 KB Output is correct
38 Correct 719 ms 5484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1408 KB Output is correct
2 Correct 17 ms 1408 KB Output is correct
3 Correct 26 ms 1408 KB Output is correct
4 Correct 14 ms 1408 KB Output is correct
5 Correct 15 ms 1408 KB Output is correct
6 Correct 17 ms 1408 KB Output is correct
7 Correct 16 ms 1408 KB Output is correct
8 Correct 16 ms 1408 KB Output is correct
9 Correct 18 ms 1408 KB Output is correct
10 Correct 16 ms 1408 KB Output is correct
11 Correct 15 ms 1408 KB Output is correct
12 Correct 14 ms 1408 KB Output is correct
13 Correct 14 ms 1408 KB Output is correct
14 Correct 14 ms 1408 KB Output is correct
15 Correct 14 ms 1408 KB Output is correct
16 Correct 7 ms 1152 KB Output is correct
17 Correct 8 ms 1152 KB Output is correct
18 Correct 7 ms 1152 KB Output is correct
19 Correct 7 ms 1152 KB Output is correct
20 Correct 7 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 755 ms 5384 KB Output is correct
2 Correct 752 ms 5392 KB Output is correct
3 Correct 765 ms 5444 KB Output is correct
4 Correct 779 ms 5368 KB Output is correct
5 Correct 755 ms 5416 KB Output is correct
6 Correct 741 ms 5368 KB Output is correct
7 Correct 744 ms 5556 KB Output is correct
8 Correct 743 ms 5384 KB Output is correct
9 Correct 774 ms 5416 KB Output is correct
10 Correct 752 ms 5368 KB Output is correct
11 Correct 771 ms 5396 KB Output is correct
12 Correct 778 ms 5428 KB Output is correct
13 Correct 754 ms 5372 KB Output is correct
14 Correct 780 ms 5496 KB Output is correct
15 Correct 779 ms 5456 KB Output is correct
16 Correct 132 ms 3756 KB Output is correct
17 Correct 144 ms 3704 KB Output is correct
18 Correct 139 ms 3676 KB Output is correct
19 Correct 144 ms 3704 KB Output is correct
20 Correct 144 ms 3880 KB Output is correct
21 Correct 177 ms 5244 KB Output is correct
22 Correct 175 ms 5240 KB Output is correct
23 Correct 157 ms 5112 KB Output is correct
24 Correct 172 ms 5240 KB Output is correct
25 Correct 183 ms 5112 KB Output is correct
26 Correct 326 ms 5112 KB Output is correct
27 Correct 340 ms 5140 KB Output is correct
28 Correct 330 ms 5152 KB Output is correct
29 Correct 324 ms 5244 KB Output is correct
30 Correct 706 ms 5404 KB Output is correct
31 Correct 706 ms 5288 KB Output is correct
32 Correct 713 ms 5496 KB Output is correct
33 Correct 717 ms 5496 KB Output is correct
34 Correct 716 ms 5372 KB Output is correct
35 Correct 701 ms 5412 KB Output is correct
36 Correct 709 ms 5532 KB Output is correct
37 Correct 724 ms 5404 KB Output is correct
38 Correct 719 ms 5484 KB Output is correct
39 Correct 16 ms 1408 KB Output is correct
40 Correct 17 ms 1408 KB Output is correct
41 Correct 26 ms 1408 KB Output is correct
42 Correct 14 ms 1408 KB Output is correct
43 Correct 15 ms 1408 KB Output is correct
44 Correct 17 ms 1408 KB Output is correct
45 Correct 16 ms 1408 KB Output is correct
46 Correct 16 ms 1408 KB Output is correct
47 Correct 18 ms 1408 KB Output is correct
48 Correct 16 ms 1408 KB Output is correct
49 Correct 15 ms 1408 KB Output is correct
50 Correct 14 ms 1408 KB Output is correct
51 Correct 14 ms 1408 KB Output is correct
52 Correct 14 ms 1408 KB Output is correct
53 Correct 14 ms 1408 KB Output is correct
54 Correct 7 ms 1152 KB Output is correct
55 Correct 8 ms 1152 KB Output is correct
56 Correct 7 ms 1152 KB Output is correct
57 Correct 7 ms 1152 KB Output is correct
58 Correct 7 ms 1152 KB Output is correct
59 Correct 1648 ms 5496 KB Output is correct
60 Correct 1622 ms 5496 KB Output is correct
61 Correct 1616 ms 5416 KB Output is correct
62 Correct 1652 ms 5624 KB Output is correct
63 Correct 1627 ms 5420 KB Output is correct
64 Correct 1851 ms 5448 KB Output is correct
65 Correct 1843 ms 5540 KB Output is correct
66 Correct 1825 ms 5464 KB Output is correct
67 Correct 1818 ms 5520 KB Output is correct
68 Correct 1842 ms 5432 KB Output is correct
69 Correct 1615 ms 5644 KB Output is correct
70 Correct 1607 ms 5416 KB Output is correct
71 Correct 1642 ms 5380 KB Output is correct
72 Correct 1630 ms 5384 KB Output is correct
73 Correct 1671 ms 5388 KB Output is correct
74 Correct 185 ms 3704 KB Output is correct
75 Correct 203 ms 3704 KB Output is correct
76 Correct 187 ms 3704 KB Output is correct
77 Correct 183 ms 3704 KB Output is correct
78 Correct 185 ms 3704 KB Output is correct