답안 #718610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718610 2023-04-04T12:12:10 Z Mauve Boat (APIO16_boat) C++14
100 / 100
379 ms 8248 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);
	
	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;
				}
			}
			dp[i][j]%=M;
		}
	}
	cout << dp[n][pts.size()-1]-1;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i=1; i<pts.size(); ++i) {
      |               ~^~~~~~~~~~~
boat.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i=0; i<pts.size(); ++i)
      |               ~^~~~~~~~~~~
boat.cpp:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for(int j=1; j<pts.size(); ++j) {
      |                ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 8136 KB Output is correct
2 Correct 292 ms 8100 KB Output is correct
3 Correct 276 ms 8052 KB Output is correct
4 Correct 269 ms 8136 KB Output is correct
5 Correct 275 ms 8200 KB Output is correct
6 Correct 185 ms 8152 KB Output is correct
7 Correct 178 ms 8076 KB Output is correct
8 Correct 192 ms 8244 KB Output is correct
9 Correct 169 ms 8132 KB Output is correct
10 Correct 161 ms 8068 KB Output is correct
11 Correct 167 ms 8140 KB Output is correct
12 Correct 165 ms 8232 KB Output is correct
13 Correct 170 ms 8148 KB Output is correct
14 Correct 154 ms 8060 KB Output is correct
15 Correct 162 ms 8156 KB Output is correct
16 Correct 52 ms 3652 KB Output is correct
17 Correct 56 ms 3744 KB Output is correct
18 Correct 59 ms 3788 KB Output is correct
19 Correct 56 ms 3788 KB Output is correct
20 Correct 55 ms 3728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 8136 KB Output is correct
2 Correct 292 ms 8100 KB Output is correct
3 Correct 276 ms 8052 KB Output is correct
4 Correct 269 ms 8136 KB Output is correct
5 Correct 275 ms 8200 KB Output is correct
6 Correct 185 ms 8152 KB Output is correct
7 Correct 178 ms 8076 KB Output is correct
8 Correct 192 ms 8244 KB Output is correct
9 Correct 169 ms 8132 KB Output is correct
10 Correct 161 ms 8068 KB Output is correct
11 Correct 167 ms 8140 KB Output is correct
12 Correct 165 ms 8232 KB Output is correct
13 Correct 170 ms 8148 KB Output is correct
14 Correct 154 ms 8060 KB Output is correct
15 Correct 162 ms 8156 KB Output is correct
16 Correct 52 ms 3652 KB Output is correct
17 Correct 56 ms 3744 KB Output is correct
18 Correct 59 ms 3788 KB Output is correct
19 Correct 56 ms 3788 KB Output is correct
20 Correct 55 ms 3728 KB Output is correct
21 Correct 316 ms 7876 KB Output is correct
22 Correct 294 ms 7884 KB Output is correct
23 Correct 304 ms 7756 KB Output is correct
24 Correct 286 ms 7676 KB Output is correct
25 Correct 310 ms 7772 KB Output is correct
26 Correct 248 ms 7620 KB Output is correct
27 Correct 269 ms 7748 KB Output is correct
28 Correct 280 ms 7616 KB Output is correct
29 Correct 239 ms 7580 KB Output is correct
30 Correct 174 ms 8140 KB Output is correct
31 Correct 162 ms 8248 KB Output is correct
32 Correct 163 ms 8140 KB Output is correct
33 Correct 156 ms 8140 KB Output is correct
34 Correct 160 ms 8096 KB Output is correct
35 Correct 278 ms 8228 KB Output is correct
36 Correct 284 ms 8080 KB Output is correct
37 Correct 262 ms 8052 KB Output is correct
38 Correct 272 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1664 KB Output is correct
2 Correct 5 ms 1620 KB Output is correct
3 Correct 4 ms 1620 KB Output is correct
4 Correct 5 ms 1608 KB Output is correct
5 Correct 5 ms 1620 KB Output is correct
6 Correct 4 ms 1620 KB Output is correct
7 Correct 5 ms 1620 KB Output is correct
8 Correct 5 ms 1620 KB Output is correct
9 Correct 4 ms 1620 KB Output is correct
10 Correct 5 ms 1612 KB Output is correct
11 Correct 4 ms 1612 KB Output is correct
12 Correct 5 ms 1620 KB Output is correct
13 Correct 4 ms 1616 KB Output is correct
14 Correct 4 ms 1684 KB Output is correct
15 Correct 4 ms 1608 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 3 ms 1236 KB Output is correct
18 Correct 3 ms 1228 KB Output is correct
19 Correct 3 ms 1236 KB Output is correct
20 Correct 3 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 8136 KB Output is correct
2 Correct 292 ms 8100 KB Output is correct
3 Correct 276 ms 8052 KB Output is correct
4 Correct 269 ms 8136 KB Output is correct
5 Correct 275 ms 8200 KB Output is correct
6 Correct 185 ms 8152 KB Output is correct
7 Correct 178 ms 8076 KB Output is correct
8 Correct 192 ms 8244 KB Output is correct
9 Correct 169 ms 8132 KB Output is correct
10 Correct 161 ms 8068 KB Output is correct
11 Correct 167 ms 8140 KB Output is correct
12 Correct 165 ms 8232 KB Output is correct
13 Correct 170 ms 8148 KB Output is correct
14 Correct 154 ms 8060 KB Output is correct
15 Correct 162 ms 8156 KB Output is correct
16 Correct 52 ms 3652 KB Output is correct
17 Correct 56 ms 3744 KB Output is correct
18 Correct 59 ms 3788 KB Output is correct
19 Correct 56 ms 3788 KB Output is correct
20 Correct 55 ms 3728 KB Output is correct
21 Correct 316 ms 7876 KB Output is correct
22 Correct 294 ms 7884 KB Output is correct
23 Correct 304 ms 7756 KB Output is correct
24 Correct 286 ms 7676 KB Output is correct
25 Correct 310 ms 7772 KB Output is correct
26 Correct 248 ms 7620 KB Output is correct
27 Correct 269 ms 7748 KB Output is correct
28 Correct 280 ms 7616 KB Output is correct
29 Correct 239 ms 7580 KB Output is correct
30 Correct 174 ms 8140 KB Output is correct
31 Correct 162 ms 8248 KB Output is correct
32 Correct 163 ms 8140 KB Output is correct
33 Correct 156 ms 8140 KB Output is correct
34 Correct 160 ms 8096 KB Output is correct
35 Correct 278 ms 8228 KB Output is correct
36 Correct 284 ms 8080 KB Output is correct
37 Correct 262 ms 8052 KB Output is correct
38 Correct 272 ms 8140 KB Output is correct
39 Correct 5 ms 1664 KB Output is correct
40 Correct 5 ms 1620 KB Output is correct
41 Correct 4 ms 1620 KB Output is correct
42 Correct 5 ms 1608 KB Output is correct
43 Correct 5 ms 1620 KB Output is correct
44 Correct 4 ms 1620 KB Output is correct
45 Correct 5 ms 1620 KB Output is correct
46 Correct 5 ms 1620 KB Output is correct
47 Correct 4 ms 1620 KB Output is correct
48 Correct 5 ms 1612 KB Output is correct
49 Correct 4 ms 1612 KB Output is correct
50 Correct 5 ms 1620 KB Output is correct
51 Correct 4 ms 1616 KB Output is correct
52 Correct 4 ms 1684 KB Output is correct
53 Correct 4 ms 1608 KB Output is correct
54 Correct 3 ms 1236 KB Output is correct
55 Correct 3 ms 1236 KB Output is correct
56 Correct 3 ms 1228 KB Output is correct
57 Correct 3 ms 1236 KB Output is correct
58 Correct 3 ms 1236 KB Output is correct
59 Correct 344 ms 8192 KB Output is correct
60 Correct 365 ms 8128 KB Output is correct
61 Correct 317 ms 8092 KB Output is correct
62 Correct 379 ms 8132 KB Output is correct
63 Correct 321 ms 8168 KB Output is correct
64 Correct 311 ms 8076 KB Output is correct
65 Correct 276 ms 8080 KB Output is correct
66 Correct 307 ms 8132 KB Output is correct
67 Correct 278 ms 8112 KB Output is correct
68 Correct 284 ms 8220 KB Output is correct
69 Correct 274 ms 8140 KB Output is correct
70 Correct 281 ms 8176 KB Output is correct
71 Correct 300 ms 8080 KB Output is correct
72 Correct 288 ms 8164 KB Output is correct
73 Correct 300 ms 8140 KB Output is correct
74 Correct 78 ms 3740 KB Output is correct
75 Correct 82 ms 3764 KB Output is correct
76 Correct 79 ms 3724 KB Output is correct
77 Correct 82 ms 3732 KB Output is correct
78 Correct 77 ms 3704 KB Output is correct