답안 #51622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51622 2018-06-19T09:25:37 Z tmwilliamlin168 Boat (APIO16_boat) C++14
100 / 100
606 ms 9404 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];
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);
	
//	cout << modI(2, M) << endl;
	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=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*modI(j, M)%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;//, cout << c[j][i-k] << " ";
				}
			}
//			cout << endl;
			dp[i][j]%=M;
//			cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	cout << dp[n][pts.size()-1]-1;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<pts.size(); ++i) {
               ~^~~~~~~~~~~
boat.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<pts.size(); ++i)
               ~^~~~~~~~~~~
boat.cpp:37:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=1; j<pts.size(); ++j) {
                ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 495 ms 8312 KB Output is correct
2 Correct 494 ms 8312 KB Output is correct
3 Correct 499 ms 8372 KB Output is correct
4 Correct 514 ms 8372 KB Output is correct
5 Correct 519 ms 8544 KB Output is correct
6 Correct 255 ms 8544 KB Output is correct
7 Correct 251 ms 8668 KB Output is correct
8 Correct 259 ms 8668 KB Output is correct
9 Correct 263 ms 8668 KB Output is correct
10 Correct 252 ms 8780 KB Output is correct
11 Correct 256 ms 8848 KB Output is correct
12 Correct 263 ms 8848 KB Output is correct
13 Correct 260 ms 8848 KB Output is correct
14 Correct 269 ms 8880 KB Output is correct
15 Correct 262 ms 8880 KB Output is correct
16 Correct 94 ms 8880 KB Output is correct
17 Correct 99 ms 8880 KB Output is correct
18 Correct 100 ms 8880 KB Output is correct
19 Correct 101 ms 8880 KB Output is correct
20 Correct 98 ms 8880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 495 ms 8312 KB Output is correct
2 Correct 494 ms 8312 KB Output is correct
3 Correct 499 ms 8372 KB Output is correct
4 Correct 514 ms 8372 KB Output is correct
5 Correct 519 ms 8544 KB Output is correct
6 Correct 255 ms 8544 KB Output is correct
7 Correct 251 ms 8668 KB Output is correct
8 Correct 259 ms 8668 KB Output is correct
9 Correct 263 ms 8668 KB Output is correct
10 Correct 252 ms 8780 KB Output is correct
11 Correct 256 ms 8848 KB Output is correct
12 Correct 263 ms 8848 KB Output is correct
13 Correct 260 ms 8848 KB Output is correct
14 Correct 269 ms 8880 KB Output is correct
15 Correct 262 ms 8880 KB Output is correct
16 Correct 94 ms 8880 KB Output is correct
17 Correct 99 ms 8880 KB Output is correct
18 Correct 100 ms 8880 KB Output is correct
19 Correct 101 ms 8880 KB Output is correct
20 Correct 98 ms 8880 KB Output is correct
21 Correct 391 ms 8880 KB Output is correct
22 Correct 401 ms 8880 KB Output is correct
23 Correct 450 ms 8880 KB Output is correct
24 Correct 434 ms 8880 KB Output is correct
25 Correct 401 ms 8880 KB Output is correct
26 Correct 437 ms 8880 KB Output is correct
27 Correct 447 ms 8880 KB Output is correct
28 Correct 448 ms 8880 KB Output is correct
29 Correct 384 ms 8880 KB Output is correct
30 Correct 312 ms 9068 KB Output is correct
31 Correct 249 ms 9068 KB Output is correct
32 Correct 256 ms 9068 KB Output is correct
33 Correct 253 ms 9080 KB Output is correct
34 Correct 248 ms 9096 KB Output is correct
35 Correct 514 ms 9168 KB Output is correct
36 Correct 492 ms 9168 KB Output is correct
37 Correct 488 ms 9168 KB Output is correct
38 Correct 502 ms 9168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9168 KB Output is correct
2 Correct 9 ms 9168 KB Output is correct
3 Correct 9 ms 9168 KB Output is correct
4 Correct 9 ms 9168 KB Output is correct
5 Correct 8 ms 9168 KB Output is correct
6 Correct 9 ms 9168 KB Output is correct
7 Correct 9 ms 9168 KB Output is correct
8 Correct 9 ms 9168 KB Output is correct
9 Correct 8 ms 9168 KB Output is correct
10 Correct 9 ms 9168 KB Output is correct
11 Correct 9 ms 9168 KB Output is correct
12 Correct 8 ms 9168 KB Output is correct
13 Correct 9 ms 9168 KB Output is correct
14 Correct 8 ms 9168 KB Output is correct
15 Correct 9 ms 9168 KB Output is correct
16 Correct 7 ms 9168 KB Output is correct
17 Correct 6 ms 9168 KB Output is correct
18 Correct 7 ms 9168 KB Output is correct
19 Correct 6 ms 9168 KB Output is correct
20 Correct 6 ms 9168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 495 ms 8312 KB Output is correct
2 Correct 494 ms 8312 KB Output is correct
3 Correct 499 ms 8372 KB Output is correct
4 Correct 514 ms 8372 KB Output is correct
5 Correct 519 ms 8544 KB Output is correct
6 Correct 255 ms 8544 KB Output is correct
7 Correct 251 ms 8668 KB Output is correct
8 Correct 259 ms 8668 KB Output is correct
9 Correct 263 ms 8668 KB Output is correct
10 Correct 252 ms 8780 KB Output is correct
11 Correct 256 ms 8848 KB Output is correct
12 Correct 263 ms 8848 KB Output is correct
13 Correct 260 ms 8848 KB Output is correct
14 Correct 269 ms 8880 KB Output is correct
15 Correct 262 ms 8880 KB Output is correct
16 Correct 94 ms 8880 KB Output is correct
17 Correct 99 ms 8880 KB Output is correct
18 Correct 100 ms 8880 KB Output is correct
19 Correct 101 ms 8880 KB Output is correct
20 Correct 98 ms 8880 KB Output is correct
21 Correct 391 ms 8880 KB Output is correct
22 Correct 401 ms 8880 KB Output is correct
23 Correct 450 ms 8880 KB Output is correct
24 Correct 434 ms 8880 KB Output is correct
25 Correct 401 ms 8880 KB Output is correct
26 Correct 437 ms 8880 KB Output is correct
27 Correct 447 ms 8880 KB Output is correct
28 Correct 448 ms 8880 KB Output is correct
29 Correct 384 ms 8880 KB Output is correct
30 Correct 312 ms 9068 KB Output is correct
31 Correct 249 ms 9068 KB Output is correct
32 Correct 256 ms 9068 KB Output is correct
33 Correct 253 ms 9080 KB Output is correct
34 Correct 248 ms 9096 KB Output is correct
35 Correct 514 ms 9168 KB Output is correct
36 Correct 492 ms 9168 KB Output is correct
37 Correct 488 ms 9168 KB Output is correct
38 Correct 502 ms 9168 KB Output is correct
39 Correct 9 ms 9168 KB Output is correct
40 Correct 9 ms 9168 KB Output is correct
41 Correct 9 ms 9168 KB Output is correct
42 Correct 9 ms 9168 KB Output is correct
43 Correct 8 ms 9168 KB Output is correct
44 Correct 9 ms 9168 KB Output is correct
45 Correct 9 ms 9168 KB Output is correct
46 Correct 9 ms 9168 KB Output is correct
47 Correct 8 ms 9168 KB Output is correct
48 Correct 9 ms 9168 KB Output is correct
49 Correct 9 ms 9168 KB Output is correct
50 Correct 8 ms 9168 KB Output is correct
51 Correct 9 ms 9168 KB Output is correct
52 Correct 8 ms 9168 KB Output is correct
53 Correct 9 ms 9168 KB Output is correct
54 Correct 7 ms 9168 KB Output is correct
55 Correct 6 ms 9168 KB Output is correct
56 Correct 7 ms 9168 KB Output is correct
57 Correct 6 ms 9168 KB Output is correct
58 Correct 6 ms 9168 KB Output is correct
59 Correct 481 ms 9168 KB Output is correct
60 Correct 478 ms 9248 KB Output is correct
61 Correct 455 ms 9288 KB Output is correct
62 Correct 429 ms 9288 KB Output is correct
63 Correct 426 ms 9288 KB Output is correct
64 Correct 448 ms 9296 KB Output is correct
65 Correct 440 ms 9296 KB Output is correct
66 Correct 442 ms 9320 KB Output is correct
67 Correct 424 ms 9320 KB Output is correct
68 Correct 503 ms 9344 KB Output is correct
69 Correct 558 ms 9344 KB Output is correct
70 Correct 523 ms 9376 KB Output is correct
71 Correct 460 ms 9376 KB Output is correct
72 Correct 442 ms 9392 KB Output is correct
73 Correct 606 ms 9404 KB Output is correct
74 Correct 119 ms 9404 KB Output is correct
75 Correct 131 ms 9404 KB Output is correct
76 Correct 121 ms 9404 KB Output is correct
77 Correct 116 ms 9404 KB Output is correct
78 Correct 109 ms 9404 KB Output is correct