답안 #51625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51625 2018-06-19T09:29:39 Z tmwilliamlin168 Boat (APIO16_boat) C++14
100 / 100
702 ms 8700 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=500, M=1e9+7;
int n, a[mxN], b[mxN];
ll dp[mxN+1][2*mxN], c[2*mxN][mxN+1], mi[mxN+1];
vector<int> pts;

inline ll modI(ll a, ll m) {
	return a<=1?a:(1-modI(m%a, a)*m)/a+m;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> a[i] >> b[i], --a[i];
		pts.push_back(a[i]);
		pts.push_back(b[i]);
	}
	sort(pts.begin(), pts.end());
	pts.resize(unique(pts.begin(), pts.end())-pts.begin());
	for(int i=2; i<=n; ++i)
		mi[i]=modI(i, M);
	for(int i=1; i<pts.size(); ++i) {
		c[i][1]=pts[i]-pts[i-1];
		for(int j=2; j<=n; ++j)
			c[i][j]=c[i][j-1]*(pts[i]-pts[i-1]+j-1)%M*mi[j]%M;
	}
	for(int i=0; i<pts.size(); ++i)
		dp[0][i]=1;
	for(int i=1; i<=n; ++i) {
		dp[i][0]=1;
		for(int j=1; j<pts.size(); ++j) {
			dp[i][j]=dp[i][j-1];
			for(int k=i, n2=0; k; --k) {
				if(pts[j]>a[k-1]&&pts[j]<=b[k-1]) {
					++n2;
					dp[i][j]+=dp[k-1][j-1]*c[j][n2]%M;
				}
			}
			dp[i][j]%=M;
		}
	}
	cout << dp[n][pts.size()-1]-1;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:29:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<pts.size(); ++i) {
               ~^~~~~~~~~~~
boat.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<pts.size(); ++i)
               ~^~~~~~~~~~~
boat.cpp:38:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=1; j<pts.size(); ++j) {
                ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 8184 KB Output is correct
2 Correct 462 ms 8292 KB Output is correct
3 Correct 470 ms 8352 KB Output is correct
4 Correct 465 ms 8396 KB Output is correct
5 Correct 478 ms 8396 KB Output is correct
6 Correct 195 ms 8396 KB Output is correct
7 Correct 171 ms 8444 KB Output is correct
8 Correct 175 ms 8444 KB Output is correct
9 Correct 177 ms 8444 KB Output is correct
10 Correct 166 ms 8444 KB Output is correct
11 Correct 186 ms 8452 KB Output is correct
12 Correct 204 ms 8452 KB Output is correct
13 Correct 185 ms 8452 KB Output is correct
14 Correct 157 ms 8452 KB Output is correct
15 Correct 171 ms 8452 KB Output is correct
16 Correct 83 ms 8452 KB Output is correct
17 Correct 88 ms 8452 KB Output is correct
18 Correct 88 ms 8452 KB Output is correct
19 Correct 88 ms 8452 KB Output is correct
20 Correct 96 ms 8452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 8184 KB Output is correct
2 Correct 462 ms 8292 KB Output is correct
3 Correct 470 ms 8352 KB Output is correct
4 Correct 465 ms 8396 KB Output is correct
5 Correct 478 ms 8396 KB Output is correct
6 Correct 195 ms 8396 KB Output is correct
7 Correct 171 ms 8444 KB Output is correct
8 Correct 175 ms 8444 KB Output is correct
9 Correct 177 ms 8444 KB Output is correct
10 Correct 166 ms 8444 KB Output is correct
11 Correct 186 ms 8452 KB Output is correct
12 Correct 204 ms 8452 KB Output is correct
13 Correct 185 ms 8452 KB Output is correct
14 Correct 157 ms 8452 KB Output is correct
15 Correct 171 ms 8452 KB Output is correct
16 Correct 83 ms 8452 KB Output is correct
17 Correct 88 ms 8452 KB Output is correct
18 Correct 88 ms 8452 KB Output is correct
19 Correct 88 ms 8452 KB Output is correct
20 Correct 96 ms 8452 KB Output is correct
21 Correct 318 ms 8452 KB Output is correct
22 Correct 317 ms 8452 KB Output is correct
23 Correct 304 ms 8452 KB Output is correct
24 Correct 405 ms 8452 KB Output is correct
25 Correct 314 ms 8452 KB Output is correct
26 Correct 314 ms 8452 KB Output is correct
27 Correct 346 ms 8452 KB Output is correct
28 Correct 311 ms 8452 KB Output is correct
29 Correct 310 ms 8452 KB Output is correct
30 Correct 184 ms 8552 KB Output is correct
31 Correct 188 ms 8552 KB Output is correct
32 Correct 176 ms 8552 KB Output is correct
33 Correct 180 ms 8552 KB Output is correct
34 Correct 171 ms 8624 KB Output is correct
35 Correct 506 ms 8624 KB Output is correct
36 Correct 485 ms 8624 KB Output is correct
37 Correct 471 ms 8624 KB Output is correct
38 Correct 482 ms 8624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8624 KB Output is correct
2 Correct 7 ms 8624 KB Output is correct
3 Correct 6 ms 8624 KB Output is correct
4 Correct 9 ms 8624 KB Output is correct
5 Correct 8 ms 8624 KB Output is correct
6 Correct 10 ms 8624 KB Output is correct
7 Correct 8 ms 8624 KB Output is correct
8 Correct 6 ms 8624 KB Output is correct
9 Correct 7 ms 8624 KB Output is correct
10 Correct 7 ms 8624 KB Output is correct
11 Correct 6 ms 8624 KB Output is correct
12 Correct 6 ms 8624 KB Output is correct
13 Correct 7 ms 8624 KB Output is correct
14 Correct 8 ms 8624 KB Output is correct
15 Correct 6 ms 8624 KB Output is correct
16 Correct 6 ms 8624 KB Output is correct
17 Correct 5 ms 8624 KB Output is correct
18 Correct 5 ms 8624 KB Output is correct
19 Correct 4 ms 8624 KB Output is correct
20 Correct 5 ms 8624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 8184 KB Output is correct
2 Correct 462 ms 8292 KB Output is correct
3 Correct 470 ms 8352 KB Output is correct
4 Correct 465 ms 8396 KB Output is correct
5 Correct 478 ms 8396 KB Output is correct
6 Correct 195 ms 8396 KB Output is correct
7 Correct 171 ms 8444 KB Output is correct
8 Correct 175 ms 8444 KB Output is correct
9 Correct 177 ms 8444 KB Output is correct
10 Correct 166 ms 8444 KB Output is correct
11 Correct 186 ms 8452 KB Output is correct
12 Correct 204 ms 8452 KB Output is correct
13 Correct 185 ms 8452 KB Output is correct
14 Correct 157 ms 8452 KB Output is correct
15 Correct 171 ms 8452 KB Output is correct
16 Correct 83 ms 8452 KB Output is correct
17 Correct 88 ms 8452 KB Output is correct
18 Correct 88 ms 8452 KB Output is correct
19 Correct 88 ms 8452 KB Output is correct
20 Correct 96 ms 8452 KB Output is correct
21 Correct 318 ms 8452 KB Output is correct
22 Correct 317 ms 8452 KB Output is correct
23 Correct 304 ms 8452 KB Output is correct
24 Correct 405 ms 8452 KB Output is correct
25 Correct 314 ms 8452 KB Output is correct
26 Correct 314 ms 8452 KB Output is correct
27 Correct 346 ms 8452 KB Output is correct
28 Correct 311 ms 8452 KB Output is correct
29 Correct 310 ms 8452 KB Output is correct
30 Correct 184 ms 8552 KB Output is correct
31 Correct 188 ms 8552 KB Output is correct
32 Correct 176 ms 8552 KB Output is correct
33 Correct 180 ms 8552 KB Output is correct
34 Correct 171 ms 8624 KB Output is correct
35 Correct 506 ms 8624 KB Output is correct
36 Correct 485 ms 8624 KB Output is correct
37 Correct 471 ms 8624 KB Output is correct
38 Correct 482 ms 8624 KB Output is correct
39 Correct 7 ms 8624 KB Output is correct
40 Correct 7 ms 8624 KB Output is correct
41 Correct 6 ms 8624 KB Output is correct
42 Correct 9 ms 8624 KB Output is correct
43 Correct 8 ms 8624 KB Output is correct
44 Correct 10 ms 8624 KB Output is correct
45 Correct 8 ms 8624 KB Output is correct
46 Correct 6 ms 8624 KB Output is correct
47 Correct 7 ms 8624 KB Output is correct
48 Correct 7 ms 8624 KB Output is correct
49 Correct 6 ms 8624 KB Output is correct
50 Correct 6 ms 8624 KB Output is correct
51 Correct 7 ms 8624 KB Output is correct
52 Correct 8 ms 8624 KB Output is correct
53 Correct 6 ms 8624 KB Output is correct
54 Correct 6 ms 8624 KB Output is correct
55 Correct 5 ms 8624 KB Output is correct
56 Correct 5 ms 8624 KB Output is correct
57 Correct 4 ms 8624 KB Output is correct
58 Correct 5 ms 8624 KB Output is correct
59 Correct 346 ms 8624 KB Output is correct
60 Correct 348 ms 8624 KB Output is correct
61 Correct 369 ms 8700 KB Output is correct
62 Correct 341 ms 8700 KB Output is correct
63 Correct 337 ms 8700 KB Output is correct
64 Correct 504 ms 8700 KB Output is correct
65 Correct 400 ms 8700 KB Output is correct
66 Correct 507 ms 8700 KB Output is correct
67 Correct 362 ms 8700 KB Output is correct
68 Correct 702 ms 8700 KB Output is correct
69 Correct 369 ms 8700 KB Output is correct
70 Correct 425 ms 8700 KB Output is correct
71 Correct 384 ms 8700 KB Output is correct
72 Correct 478 ms 8700 KB Output is correct
73 Correct 362 ms 8700 KB Output is correct
74 Correct 98 ms 8700 KB Output is correct
75 Correct 98 ms 8700 KB Output is correct
76 Correct 106 ms 8700 KB Output is correct
77 Correct 115 ms 8700 KB Output is correct
78 Correct 125 ms 8700 KB Output is correct