답안 #53349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53349 2018-06-29T14:59:43 Z junodeveloper Boat (APIO16_boat) C++11
100 / 100
1280 ms 10640 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++)
				sum[i][j] = (sum[i][j] + 1ll
				* fac[j-1] * inv[k-1] % MOD * inv[j-k] % MOD
				* bigfac[i][k] % MOD * inv[k]) % 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 23 ms 9976 KB Output is correct
2 Correct 22 ms 9976 KB Output is correct
3 Correct 21 ms 9992 KB Output is correct
4 Correct 21 ms 10068 KB Output is correct
5 Correct 22 ms 10068 KB Output is correct
6 Correct 22 ms 10452 KB Output is correct
7 Correct 21 ms 10452 KB Output is correct
8 Correct 28 ms 10452 KB Output is correct
9 Correct 23 ms 10532 KB Output is correct
10 Correct 23 ms 10532 KB Output is correct
11 Correct 22 ms 10532 KB Output is correct
12 Correct 21 ms 10532 KB Output is correct
13 Correct 22 ms 10532 KB Output is correct
14 Correct 22 ms 10532 KB Output is correct
15 Correct 29 ms 10532 KB Output is correct
16 Correct 11 ms 10532 KB Output is correct
17 Correct 11 ms 10532 KB Output is correct
18 Correct 13 ms 10532 KB Output is correct
19 Correct 12 ms 10532 KB Output is correct
20 Correct 9 ms 10532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 9976 KB Output is correct
2 Correct 22 ms 9976 KB Output is correct
3 Correct 21 ms 9992 KB Output is correct
4 Correct 21 ms 10068 KB Output is correct
5 Correct 22 ms 10068 KB Output is correct
6 Correct 22 ms 10452 KB Output is correct
7 Correct 21 ms 10452 KB Output is correct
8 Correct 28 ms 10452 KB Output is correct
9 Correct 23 ms 10532 KB Output is correct
10 Correct 23 ms 10532 KB Output is correct
11 Correct 22 ms 10532 KB Output is correct
12 Correct 21 ms 10532 KB Output is correct
13 Correct 22 ms 10532 KB Output is correct
14 Correct 22 ms 10532 KB Output is correct
15 Correct 29 ms 10532 KB Output is correct
16 Correct 11 ms 10532 KB Output is correct
17 Correct 11 ms 10532 KB Output is correct
18 Correct 13 ms 10532 KB Output is correct
19 Correct 12 ms 10532 KB Output is correct
20 Correct 9 ms 10532 KB Output is correct
21 Correct 595 ms 10532 KB Output is correct
22 Correct 505 ms 10532 KB Output is correct
23 Correct 592 ms 10532 KB Output is correct
24 Correct 558 ms 10532 KB Output is correct
25 Correct 545 ms 10532 KB Output is correct
26 Correct 828 ms 10532 KB Output is correct
27 Correct 912 ms 10532 KB Output is correct
28 Correct 858 ms 10532 KB Output is correct
29 Correct 787 ms 10532 KB Output is correct
30 Correct 23 ms 10532 KB Output is correct
31 Correct 23 ms 10532 KB Output is correct
32 Correct 23 ms 10532 KB Output is correct
33 Correct 26 ms 10532 KB Output is correct
34 Correct 22 ms 10532 KB Output is correct
35 Correct 23 ms 10532 KB Output is correct
36 Correct 23 ms 10532 KB Output is correct
37 Correct 23 ms 10532 KB Output is correct
38 Correct 24 ms 10532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 10532 KB Output is correct
2 Correct 7 ms 10532 KB Output is correct
3 Correct 9 ms 10532 KB Output is correct
4 Correct 10 ms 10532 KB Output is correct
5 Correct 8 ms 10532 KB Output is correct
6 Correct 14 ms 10532 KB Output is correct
7 Correct 16 ms 10532 KB Output is correct
8 Correct 12 ms 10532 KB Output is correct
9 Correct 12 ms 10532 KB Output is correct
10 Correct 13 ms 10532 KB Output is correct
11 Correct 8 ms 10532 KB Output is correct
12 Correct 9 ms 10532 KB Output is correct
13 Correct 8 ms 10532 KB Output is correct
14 Correct 9 ms 10532 KB Output is correct
15 Correct 9 ms 10532 KB Output is correct
16 Correct 6 ms 10532 KB Output is correct
17 Correct 7 ms 10532 KB Output is correct
18 Correct 6 ms 10532 KB Output is correct
19 Correct 7 ms 10532 KB Output is correct
20 Correct 6 ms 10532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 9976 KB Output is correct
2 Correct 22 ms 9976 KB Output is correct
3 Correct 21 ms 9992 KB Output is correct
4 Correct 21 ms 10068 KB Output is correct
5 Correct 22 ms 10068 KB Output is correct
6 Correct 22 ms 10452 KB Output is correct
7 Correct 21 ms 10452 KB Output is correct
8 Correct 28 ms 10452 KB Output is correct
9 Correct 23 ms 10532 KB Output is correct
10 Correct 23 ms 10532 KB Output is correct
11 Correct 22 ms 10532 KB Output is correct
12 Correct 21 ms 10532 KB Output is correct
13 Correct 22 ms 10532 KB Output is correct
14 Correct 22 ms 10532 KB Output is correct
15 Correct 29 ms 10532 KB Output is correct
16 Correct 11 ms 10532 KB Output is correct
17 Correct 11 ms 10532 KB Output is correct
18 Correct 13 ms 10532 KB Output is correct
19 Correct 12 ms 10532 KB Output is correct
20 Correct 9 ms 10532 KB Output is correct
21 Correct 595 ms 10532 KB Output is correct
22 Correct 505 ms 10532 KB Output is correct
23 Correct 592 ms 10532 KB Output is correct
24 Correct 558 ms 10532 KB Output is correct
25 Correct 545 ms 10532 KB Output is correct
26 Correct 828 ms 10532 KB Output is correct
27 Correct 912 ms 10532 KB Output is correct
28 Correct 858 ms 10532 KB Output is correct
29 Correct 787 ms 10532 KB Output is correct
30 Correct 23 ms 10532 KB Output is correct
31 Correct 23 ms 10532 KB Output is correct
32 Correct 23 ms 10532 KB Output is correct
33 Correct 26 ms 10532 KB Output is correct
34 Correct 22 ms 10532 KB Output is correct
35 Correct 23 ms 10532 KB Output is correct
36 Correct 23 ms 10532 KB Output is correct
37 Correct 23 ms 10532 KB Output is correct
38 Correct 24 ms 10532 KB Output is correct
39 Correct 8 ms 10532 KB Output is correct
40 Correct 7 ms 10532 KB Output is correct
41 Correct 9 ms 10532 KB Output is correct
42 Correct 10 ms 10532 KB Output is correct
43 Correct 8 ms 10532 KB Output is correct
44 Correct 14 ms 10532 KB Output is correct
45 Correct 16 ms 10532 KB Output is correct
46 Correct 12 ms 10532 KB Output is correct
47 Correct 12 ms 10532 KB Output is correct
48 Correct 13 ms 10532 KB Output is correct
49 Correct 8 ms 10532 KB Output is correct
50 Correct 9 ms 10532 KB Output is correct
51 Correct 8 ms 10532 KB Output is correct
52 Correct 9 ms 10532 KB Output is correct
53 Correct 9 ms 10532 KB Output is correct
54 Correct 6 ms 10532 KB Output is correct
55 Correct 7 ms 10532 KB Output is correct
56 Correct 6 ms 10532 KB Output is correct
57 Correct 7 ms 10532 KB Output is correct
58 Correct 6 ms 10532 KB Output is correct
59 Correct 615 ms 10532 KB Output is correct
60 Correct 529 ms 10532 KB Output is correct
61 Correct 502 ms 10532 KB Output is correct
62 Correct 630 ms 10544 KB Output is correct
63 Correct 626 ms 10544 KB Output is correct
64 Correct 1270 ms 10544 KB Output is correct
65 Correct 1280 ms 10592 KB Output is correct
66 Correct 1146 ms 10592 KB Output is correct
67 Correct 1043 ms 10640 KB Output is correct
68 Correct 1050 ms 10640 KB Output is correct
69 Correct 470 ms 10640 KB Output is correct
70 Correct 497 ms 10640 KB Output is correct
71 Correct 442 ms 10640 KB Output is correct
72 Correct 453 ms 10640 KB Output is correct
73 Correct 532 ms 10640 KB Output is correct
74 Correct 109 ms 10640 KB Output is correct
75 Correct 121 ms 10640 KB Output is correct
76 Correct 114 ms 10640 KB Output is correct
77 Correct 117 ms 10640 KB Output is correct
78 Correct 115 ms 10640 KB Output is correct