답안 #200602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200602 2020-02-07T14:15:54 Z dennisstar Boat (APIO16_boat) C++17
100 / 100
394 ms 4600 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
#define unq(V) (V).erase(unique(all(V)), (V).end())
using namespace std;
typedef long long ll;
typedef vector<int> vim;

const ll MOD = 1e9+7;

ll getinv(ll x) {
	ll ret=1;
	for (int i=30; i>=0; i--) {
		ret=ret*ret%MOD;
		if ((1<<i)&(MOD-2)) ret=ret*x%MOD;
	}
	return ret;
}

int N, A[505], B[505]; vim cp;
ll D[505][1010], L[1010], inv[505];

int main() {
	for (int i=1; i<=500; i++) inv[i]=getinv(i);

	scanf("%d", &N);
	for (int i=1; i<=N; i++) scanf("%d %d", &A[i], &B[i]), cp.eb(A[i]), cp.eb(B[i]+1);
	sort(all(cp)); unq(cp);
	for (int i=1; i<=N; i++) A[i]=upper_bound(all(cp), A[i])-cp.begin();
	for (int i=1; i<=N; i++) B[i]=upper_bound(all(cp), B[i])-cp.begin();
	for (int i=1; i<cp.size(); i++) L[i]=cp[i]-cp[i-1];
	fill(D[0], D[0]+1010, 1);

	for (int i=1; i<=N; i++) {
		D[i][0]=1;
		for (int j=A[i]; j<=B[i]; j++) {
			D[i][j]=D[i-1][j-1]*L[j]%MOD;
			int cnt=1; ll num=L[j]-1;
			for (int k=i-1; k; k--) if (A[k]<=j&&j<=B[k]) {
				cnt++;
				num*=(L[j]+cnt-2)*inv[cnt]%MOD; num%=MOD;
				D[i][j]+=D[k-1][j-1]*num; D[i][j]%=MOD;
			}
		}
		for (int j=1; j<cp.size(); j++) D[i][j]+=D[i-1][j]+D[i][j-1]-D[i-1][j-1]+MOD, D[i][j]%=MOD;
	}

	printf("%lld\n", (D[N][cp.size()-1]+MOD-1)%MOD);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:31:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=1; i<cp.size(); i++) L[i]=cp[i]-cp[i-1];
                ~^~~~~~~~~~
boat.cpp:45:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=1; j<cp.size(); j++) D[i][j]+=D[i-1][j]+D[i][j-1]-D[i-1][j-1]+MOD, D[i][j]%=MOD;
                 ~^~~~~~~~~~
boat.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
boat.cpp:27:68: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=1; i<=N; i++) scanf("%d %d", &A[i], &B[i]), cp.eb(A[i]), cp.eb(B[i]+1);
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4344 KB Output is correct
2 Correct 12 ms 4348 KB Output is correct
3 Correct 13 ms 4348 KB Output is correct
4 Correct 12 ms 4340 KB Output is correct
5 Correct 12 ms 4344 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4348 KB Output is correct
8 Correct 13 ms 4344 KB Output is correct
9 Correct 12 ms 4344 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4344 KB Output is correct
12 Correct 20 ms 4344 KB Output is correct
13 Correct 13 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 8 ms 2936 KB Output is correct
17 Correct 8 ms 3064 KB Output is correct
18 Correct 8 ms 3064 KB Output is correct
19 Correct 8 ms 3064 KB Output is correct
20 Correct 8 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4344 KB Output is correct
2 Correct 12 ms 4348 KB Output is correct
3 Correct 13 ms 4348 KB Output is correct
4 Correct 12 ms 4340 KB Output is correct
5 Correct 12 ms 4344 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4348 KB Output is correct
8 Correct 13 ms 4344 KB Output is correct
9 Correct 12 ms 4344 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4344 KB Output is correct
12 Correct 20 ms 4344 KB Output is correct
13 Correct 13 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 8 ms 2936 KB Output is correct
17 Correct 8 ms 3064 KB Output is correct
18 Correct 8 ms 3064 KB Output is correct
19 Correct 8 ms 3064 KB Output is correct
20 Correct 8 ms 3064 KB Output is correct
21 Correct 184 ms 4312 KB Output is correct
22 Correct 177 ms 4344 KB Output is correct
23 Correct 155 ms 4344 KB Output is correct
24 Correct 176 ms 4344 KB Output is correct
25 Correct 180 ms 4344 KB Output is correct
26 Correct 342 ms 4292 KB Output is correct
27 Correct 336 ms 4456 KB Output is correct
28 Correct 340 ms 4320 KB Output is correct
29 Correct 330 ms 4344 KB Output is correct
30 Correct 12 ms 4344 KB Output is correct
31 Correct 12 ms 4344 KB Output is correct
32 Correct 13 ms 4344 KB Output is correct
33 Correct 13 ms 4348 KB Output is correct
34 Correct 12 ms 4344 KB Output is correct
35 Correct 13 ms 4344 KB Output is correct
36 Correct 15 ms 4344 KB Output is correct
37 Correct 13 ms 4344 KB Output is correct
38 Correct 13 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 7 ms 888 KB Output is correct
4 Correct 7 ms 888 KB Output is correct
5 Correct 7 ms 1016 KB Output is correct
6 Correct 8 ms 888 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 9 ms 888 KB Output is correct
9 Correct 8 ms 888 KB Output is correct
10 Correct 9 ms 892 KB Output is correct
11 Correct 7 ms 888 KB Output is correct
12 Correct 6 ms 888 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 6 ms 888 KB Output is correct
15 Correct 7 ms 888 KB Output is correct
16 Correct 7 ms 760 KB Output is correct
17 Correct 6 ms 760 KB Output is correct
18 Correct 7 ms 888 KB Output is correct
19 Correct 6 ms 764 KB Output is correct
20 Correct 6 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4344 KB Output is correct
2 Correct 12 ms 4348 KB Output is correct
3 Correct 13 ms 4348 KB Output is correct
4 Correct 12 ms 4340 KB Output is correct
5 Correct 12 ms 4344 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4348 KB Output is correct
8 Correct 13 ms 4344 KB Output is correct
9 Correct 12 ms 4344 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4344 KB Output is correct
12 Correct 20 ms 4344 KB Output is correct
13 Correct 13 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 8 ms 2936 KB Output is correct
17 Correct 8 ms 3064 KB Output is correct
18 Correct 8 ms 3064 KB Output is correct
19 Correct 8 ms 3064 KB Output is correct
20 Correct 8 ms 3064 KB Output is correct
21 Correct 184 ms 4312 KB Output is correct
22 Correct 177 ms 4344 KB Output is correct
23 Correct 155 ms 4344 KB Output is correct
24 Correct 176 ms 4344 KB Output is correct
25 Correct 180 ms 4344 KB Output is correct
26 Correct 342 ms 4292 KB Output is correct
27 Correct 336 ms 4456 KB Output is correct
28 Correct 340 ms 4320 KB Output is correct
29 Correct 330 ms 4344 KB Output is correct
30 Correct 12 ms 4344 KB Output is correct
31 Correct 12 ms 4344 KB Output is correct
32 Correct 13 ms 4344 KB Output is correct
33 Correct 13 ms 4348 KB Output is correct
34 Correct 12 ms 4344 KB Output is correct
35 Correct 13 ms 4344 KB Output is correct
36 Correct 15 ms 4344 KB Output is correct
37 Correct 13 ms 4344 KB Output is correct
38 Correct 13 ms 4344 KB Output is correct
39 Correct 7 ms 888 KB Output is correct
40 Correct 7 ms 888 KB Output is correct
41 Correct 7 ms 888 KB Output is correct
42 Correct 7 ms 888 KB Output is correct
43 Correct 7 ms 1016 KB Output is correct
44 Correct 8 ms 888 KB Output is correct
45 Correct 8 ms 888 KB Output is correct
46 Correct 9 ms 888 KB Output is correct
47 Correct 8 ms 888 KB Output is correct
48 Correct 9 ms 892 KB Output is correct
49 Correct 7 ms 888 KB Output is correct
50 Correct 6 ms 888 KB Output is correct
51 Correct 7 ms 888 KB Output is correct
52 Correct 6 ms 888 KB Output is correct
53 Correct 7 ms 888 KB Output is correct
54 Correct 7 ms 760 KB Output is correct
55 Correct 6 ms 760 KB Output is correct
56 Correct 7 ms 888 KB Output is correct
57 Correct 6 ms 764 KB Output is correct
58 Correct 6 ms 764 KB Output is correct
59 Correct 199 ms 4344 KB Output is correct
60 Correct 193 ms 4344 KB Output is correct
61 Correct 171 ms 4344 KB Output is correct
62 Correct 206 ms 4600 KB Output is correct
63 Correct 188 ms 4344 KB Output is correct
64 Correct 394 ms 4344 KB Output is correct
65 Correct 393 ms 4428 KB Output is correct
66 Correct 392 ms 4344 KB Output is correct
67 Correct 392 ms 4344 KB Output is correct
68 Correct 394 ms 4344 KB Output is correct
69 Correct 160 ms 4320 KB Output is correct
70 Correct 157 ms 4344 KB Output is correct
71 Correct 165 ms 4472 KB Output is correct
72 Correct 173 ms 4476 KB Output is correct
73 Correct 185 ms 4344 KB Output is correct
74 Correct 49 ms 3064 KB Output is correct
75 Correct 53 ms 3064 KB Output is correct
76 Correct 61 ms 3064 KB Output is correct
77 Correct 53 ms 3192 KB Output is correct
78 Correct 53 ms 3064 KB Output is correct