답안 #53350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53350 2018-06-29T15:01:09 Z junodeveloper Boat (APIO16_boat) C++11
100 / 100
1108 ms 10748 KB
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int n, a[510], b[510];
int dp[510][1010], dp2[510][1010];
int sum[1010][510], scnt[1010][510], fac[510]={1}, inv[510]={1}, bigfac[1010][510];
vector<int> Vx;
int modpow(int a, long long n, int mod = MOD) {
	int r = 1, b = a;
	while(n > 0) {
		if(n & 1) r = 1ll * r * b % mod;
		b = 1ll * b * b % mod;
		n >>= 1;
	}
	return r;
}
int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%d%d", a+i, b+i); b[i]++;
		Vx.push_back(a[i]);
		Vx.push_back(b[i]);
	}
	sort(ALL(Vx));
	Vx.erase(unique(ALL(Vx)), Vx.end());
	for(int i=1; i<=500; i++) { 
		fac[i] = 1ll * fac[i-1] * i % MOD;
		inv[i] = modpow(fac[i], MOD - 2);
	}
	for(int i=1; i<SZ(Vx); i++) {
		int len = Vx[i] - Vx[i-1];
		bigfac[i][0] = 1;
		for(int j=1; j<=n; j++)
			scnt[i][j] = scnt[i][j-1] + (min(b[j], Vx[i]) - max(a[j], Vx[i-1]) > 0);
		for(int j=1; j<=n; j++)
			bigfac[i][j] = 1ll * bigfac[i][j-1] * (len - j + 1) % MOD;
		for(int j=1; j<=scnt[i][n]; j++) {
			for(int k=1; k<=j; k++) {
				int c1 = 1ll * fac[j-1] * inv[k-1] % MOD * inv[j-k] % MOD;
				int c2 = 1ll * bigfac[i][k] * inv[k] % MOD;
				sum[i][j] = (sum[i][j] + 1ll * c1 * c2 % MOD) % MOD;
			}
		}
	}
	int res = 0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<SZ(Vx); j++) {
			if(!(min(b[i], Vx[j]) - max(a[i], Vx[j-1]) > 0)) continue;
			dp[i][j] = sum[j][scnt[j][i]];
			for(int k=1; k<i; k++) {
				dp[i][j] = (dp[i][j] + 1ll * dp2[k][j-1] * sum[j][scnt[j][i] - scnt[j][k]] % MOD) % MOD;
			}
			res = (res + dp[i][j]) % MOD;
		}
		for(int j=1; j<SZ(Vx); j++) dp2[i][j] = (dp2[i][j-1] + dp[i][j]) % MOD;
	}
	// sum[s][cnt] : sum(C(cnt-1, i-1) * C(Vx[s]-Vx[s-1], i)) for 1<=i<=cnt
	printf("%d", res);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
boat.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", a+i, b+i); b[i]++;
   ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 9976 KB Output is correct
2 Correct 26 ms 10104 KB Output is correct
3 Correct 24 ms 10132 KB Output is correct
4 Correct 22 ms 10132 KB Output is correct
5 Correct 23 ms 10132 KB Output is correct
6 Correct 23 ms 10544 KB Output is correct
7 Correct 22 ms 10544 KB Output is correct
8 Correct 23 ms 10544 KB Output is correct
9 Correct 23 ms 10544 KB Output is correct
10 Correct 27 ms 10544 KB Output is correct
11 Correct 26 ms 10544 KB Output is correct
12 Correct 22 ms 10544 KB Output is correct
13 Correct 22 ms 10544 KB Output is correct
14 Correct 22 ms 10544 KB Output is correct
15 Correct 23 ms 10544 KB Output is correct
16 Correct 11 ms 10544 KB Output is correct
17 Correct 10 ms 10544 KB Output is correct
18 Correct 11 ms 10544 KB Output is correct
19 Correct 10 ms 10544 KB Output is correct
20 Correct 10 ms 10544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 9976 KB Output is correct
2 Correct 26 ms 10104 KB Output is correct
3 Correct 24 ms 10132 KB Output is correct
4 Correct 22 ms 10132 KB Output is correct
5 Correct 23 ms 10132 KB Output is correct
6 Correct 23 ms 10544 KB Output is correct
7 Correct 22 ms 10544 KB Output is correct
8 Correct 23 ms 10544 KB Output is correct
9 Correct 23 ms 10544 KB Output is correct
10 Correct 27 ms 10544 KB Output is correct
11 Correct 26 ms 10544 KB Output is correct
12 Correct 22 ms 10544 KB Output is correct
13 Correct 22 ms 10544 KB Output is correct
14 Correct 22 ms 10544 KB Output is correct
15 Correct 23 ms 10544 KB Output is correct
16 Correct 11 ms 10544 KB Output is correct
17 Correct 10 ms 10544 KB Output is correct
18 Correct 11 ms 10544 KB Output is correct
19 Correct 10 ms 10544 KB Output is correct
20 Correct 10 ms 10544 KB Output is correct
21 Correct 581 ms 10544 KB Output is correct
22 Correct 682 ms 10544 KB Output is correct
23 Correct 607 ms 10544 KB Output is correct
24 Correct 585 ms 10544 KB Output is correct
25 Correct 589 ms 10544 KB Output is correct
26 Correct 879 ms 10544 KB Output is correct
27 Correct 940 ms 10544 KB Output is correct
28 Correct 886 ms 10544 KB Output is correct
29 Correct 961 ms 10544 KB Output is correct
30 Correct 25 ms 10544 KB Output is correct
31 Correct 25 ms 10544 KB Output is correct
32 Correct 27 ms 10604 KB Output is correct
33 Correct 24 ms 10604 KB Output is correct
34 Correct 25 ms 10604 KB Output is correct
35 Correct 29 ms 10604 KB Output is correct
36 Correct 24 ms 10604 KB Output is correct
37 Correct 25 ms 10604 KB Output is correct
38 Correct 24 ms 10604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10604 KB Output is correct
2 Correct 8 ms 10604 KB Output is correct
3 Correct 8 ms 10604 KB Output is correct
4 Correct 9 ms 10604 KB Output is correct
5 Correct 16 ms 10604 KB Output is correct
6 Correct 14 ms 10604 KB Output is correct
7 Correct 14 ms 10604 KB Output is correct
8 Correct 13 ms 10604 KB Output is correct
9 Correct 12 ms 10604 KB Output is correct
10 Correct 13 ms 10604 KB Output is correct
11 Correct 9 ms 10604 KB Output is correct
12 Correct 9 ms 10604 KB Output is correct
13 Correct 8 ms 10604 KB Output is correct
14 Correct 8 ms 10604 KB Output is correct
15 Correct 11 ms 10604 KB Output is correct
16 Correct 6 ms 10604 KB Output is correct
17 Correct 6 ms 10604 KB Output is correct
18 Correct 8 ms 10604 KB Output is correct
19 Correct 6 ms 10604 KB Output is correct
20 Correct 7 ms 10604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 9976 KB Output is correct
2 Correct 26 ms 10104 KB Output is correct
3 Correct 24 ms 10132 KB Output is correct
4 Correct 22 ms 10132 KB Output is correct
5 Correct 23 ms 10132 KB Output is correct
6 Correct 23 ms 10544 KB Output is correct
7 Correct 22 ms 10544 KB Output is correct
8 Correct 23 ms 10544 KB Output is correct
9 Correct 23 ms 10544 KB Output is correct
10 Correct 27 ms 10544 KB Output is correct
11 Correct 26 ms 10544 KB Output is correct
12 Correct 22 ms 10544 KB Output is correct
13 Correct 22 ms 10544 KB Output is correct
14 Correct 22 ms 10544 KB Output is correct
15 Correct 23 ms 10544 KB Output is correct
16 Correct 11 ms 10544 KB Output is correct
17 Correct 10 ms 10544 KB Output is correct
18 Correct 11 ms 10544 KB Output is correct
19 Correct 10 ms 10544 KB Output is correct
20 Correct 10 ms 10544 KB Output is correct
21 Correct 581 ms 10544 KB Output is correct
22 Correct 682 ms 10544 KB Output is correct
23 Correct 607 ms 10544 KB Output is correct
24 Correct 585 ms 10544 KB Output is correct
25 Correct 589 ms 10544 KB Output is correct
26 Correct 879 ms 10544 KB Output is correct
27 Correct 940 ms 10544 KB Output is correct
28 Correct 886 ms 10544 KB Output is correct
29 Correct 961 ms 10544 KB Output is correct
30 Correct 25 ms 10544 KB Output is correct
31 Correct 25 ms 10544 KB Output is correct
32 Correct 27 ms 10604 KB Output is correct
33 Correct 24 ms 10604 KB Output is correct
34 Correct 25 ms 10604 KB Output is correct
35 Correct 29 ms 10604 KB Output is correct
36 Correct 24 ms 10604 KB Output is correct
37 Correct 25 ms 10604 KB Output is correct
38 Correct 24 ms 10604 KB Output is correct
39 Correct 9 ms 10604 KB Output is correct
40 Correct 8 ms 10604 KB Output is correct
41 Correct 8 ms 10604 KB Output is correct
42 Correct 9 ms 10604 KB Output is correct
43 Correct 16 ms 10604 KB Output is correct
44 Correct 14 ms 10604 KB Output is correct
45 Correct 14 ms 10604 KB Output is correct
46 Correct 13 ms 10604 KB Output is correct
47 Correct 12 ms 10604 KB Output is correct
48 Correct 13 ms 10604 KB Output is correct
49 Correct 9 ms 10604 KB Output is correct
50 Correct 9 ms 10604 KB Output is correct
51 Correct 8 ms 10604 KB Output is correct
52 Correct 8 ms 10604 KB Output is correct
53 Correct 11 ms 10604 KB Output is correct
54 Correct 6 ms 10604 KB Output is correct
55 Correct 6 ms 10604 KB Output is correct
56 Correct 8 ms 10604 KB Output is correct
57 Correct 6 ms 10604 KB Output is correct
58 Correct 7 ms 10604 KB Output is correct
59 Correct 722 ms 10604 KB Output is correct
60 Correct 621 ms 10620 KB Output is correct
61 Correct 588 ms 10620 KB Output is correct
62 Correct 669 ms 10644 KB Output is correct
63 Correct 602 ms 10644 KB Output is correct
64 Correct 1055 ms 10748 KB Output is correct
65 Correct 1028 ms 10748 KB Output is correct
66 Correct 1078 ms 10748 KB Output is correct
67 Correct 1108 ms 10748 KB Output is correct
68 Correct 1020 ms 10748 KB Output is correct
69 Correct 519 ms 10748 KB Output is correct
70 Correct 463 ms 10748 KB Output is correct
71 Correct 594 ms 10748 KB Output is correct
72 Correct 475 ms 10748 KB Output is correct
73 Correct 473 ms 10748 KB Output is correct
74 Correct 107 ms 10748 KB Output is correct
75 Correct 115 ms 10748 KB Output is correct
76 Correct 109 ms 10748 KB Output is correct
77 Correct 108 ms 10748 KB Output is correct
78 Correct 110 ms 10748 KB Output is correct