답안 #53348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53348 2018-06-29T14:59:08 Z junodeveloper Boat (APIO16_boat) C++11
58 / 100
2000 ms 10768 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<=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 1531 ms 10144 KB Output is correct
2 Correct 1521 ms 10144 KB Output is correct
3 Correct 1549 ms 10160 KB Output is correct
4 Correct 1495 ms 10160 KB Output is correct
5 Correct 1462 ms 10160 KB Output is correct
6 Correct 1531 ms 10544 KB Output is correct
7 Correct 1531 ms 10544 KB Output is correct
8 Correct 1480 ms 10624 KB Output is correct
9 Correct 1483 ms 10624 KB Output is correct
10 Correct 1487 ms 10624 KB Output is correct
11 Correct 1452 ms 10668 KB Output is correct
12 Correct 1547 ms 10668 KB Output is correct
13 Correct 1699 ms 10768 KB Output is correct
14 Correct 1569 ms 10768 KB Output is correct
15 Correct 1608 ms 10768 KB Output is correct
16 Correct 281 ms 10768 KB Output is correct
17 Correct 329 ms 10768 KB Output is correct
18 Correct 284 ms 10768 KB Output is correct
19 Correct 354 ms 10768 KB Output is correct
20 Correct 300 ms 10768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1531 ms 10144 KB Output is correct
2 Correct 1521 ms 10144 KB Output is correct
3 Correct 1549 ms 10160 KB Output is correct
4 Correct 1495 ms 10160 KB Output is correct
5 Correct 1462 ms 10160 KB Output is correct
6 Correct 1531 ms 10544 KB Output is correct
7 Correct 1531 ms 10544 KB Output is correct
8 Correct 1480 ms 10624 KB Output is correct
9 Correct 1483 ms 10624 KB Output is correct
10 Correct 1487 ms 10624 KB Output is correct
11 Correct 1452 ms 10668 KB Output is correct
12 Correct 1547 ms 10668 KB Output is correct
13 Correct 1699 ms 10768 KB Output is correct
14 Correct 1569 ms 10768 KB Output is correct
15 Correct 1608 ms 10768 KB Output is correct
16 Correct 281 ms 10768 KB Output is correct
17 Correct 329 ms 10768 KB Output is correct
18 Correct 284 ms 10768 KB Output is correct
19 Correct 354 ms 10768 KB Output is correct
20 Correct 300 ms 10768 KB Output is correct
21 Correct 1620 ms 10768 KB Output is correct
22 Correct 1621 ms 10768 KB Output is correct
23 Correct 1619 ms 10768 KB Output is correct
24 Correct 1756 ms 10768 KB Output is correct
25 Correct 1783 ms 10768 KB Output is correct
26 Correct 1848 ms 10768 KB Output is correct
27 Correct 1885 ms 10768 KB Output is correct
28 Correct 1770 ms 10768 KB Output is correct
29 Correct 1950 ms 10768 KB Output is correct
30 Correct 1507 ms 10768 KB Output is correct
31 Correct 1508 ms 10768 KB Output is correct
32 Correct 1461 ms 10768 KB Output is correct
33 Correct 1490 ms 10768 KB Output is correct
34 Correct 1723 ms 10768 KB Output is correct
35 Correct 1749 ms 10768 KB Output is correct
36 Correct 1691 ms 10768 KB Output is correct
37 Correct 1572 ms 10768 KB Output is correct
38 Correct 1546 ms 10768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 10768 KB Output is correct
2 Correct 20 ms 10768 KB Output is correct
3 Correct 18 ms 10768 KB Output is correct
4 Correct 19 ms 10768 KB Output is correct
5 Correct 24 ms 10768 KB Output is correct
6 Correct 20 ms 10768 KB Output is correct
7 Correct 19 ms 10768 KB Output is correct
8 Correct 22 ms 10768 KB Output is correct
9 Correct 27 ms 10768 KB Output is correct
10 Correct 21 ms 10768 KB Output is correct
11 Correct 19 ms 10768 KB Output is correct
12 Correct 19 ms 10768 KB Output is correct
13 Correct 21 ms 10768 KB Output is correct
14 Correct 24 ms 10768 KB Output is correct
15 Correct 24 ms 10768 KB Output is correct
16 Correct 12 ms 10768 KB Output is correct
17 Correct 12 ms 10768 KB Output is correct
18 Correct 12 ms 10768 KB Output is correct
19 Correct 16 ms 10768 KB Output is correct
20 Correct 17 ms 10768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1531 ms 10144 KB Output is correct
2 Correct 1521 ms 10144 KB Output is correct
3 Correct 1549 ms 10160 KB Output is correct
4 Correct 1495 ms 10160 KB Output is correct
5 Correct 1462 ms 10160 KB Output is correct
6 Correct 1531 ms 10544 KB Output is correct
7 Correct 1531 ms 10544 KB Output is correct
8 Correct 1480 ms 10624 KB Output is correct
9 Correct 1483 ms 10624 KB Output is correct
10 Correct 1487 ms 10624 KB Output is correct
11 Correct 1452 ms 10668 KB Output is correct
12 Correct 1547 ms 10668 KB Output is correct
13 Correct 1699 ms 10768 KB Output is correct
14 Correct 1569 ms 10768 KB Output is correct
15 Correct 1608 ms 10768 KB Output is correct
16 Correct 281 ms 10768 KB Output is correct
17 Correct 329 ms 10768 KB Output is correct
18 Correct 284 ms 10768 KB Output is correct
19 Correct 354 ms 10768 KB Output is correct
20 Correct 300 ms 10768 KB Output is correct
21 Correct 1620 ms 10768 KB Output is correct
22 Correct 1621 ms 10768 KB Output is correct
23 Correct 1619 ms 10768 KB Output is correct
24 Correct 1756 ms 10768 KB Output is correct
25 Correct 1783 ms 10768 KB Output is correct
26 Correct 1848 ms 10768 KB Output is correct
27 Correct 1885 ms 10768 KB Output is correct
28 Correct 1770 ms 10768 KB Output is correct
29 Correct 1950 ms 10768 KB Output is correct
30 Correct 1507 ms 10768 KB Output is correct
31 Correct 1508 ms 10768 KB Output is correct
32 Correct 1461 ms 10768 KB Output is correct
33 Correct 1490 ms 10768 KB Output is correct
34 Correct 1723 ms 10768 KB Output is correct
35 Correct 1749 ms 10768 KB Output is correct
36 Correct 1691 ms 10768 KB Output is correct
37 Correct 1572 ms 10768 KB Output is correct
38 Correct 1546 ms 10768 KB Output is correct
39 Correct 20 ms 10768 KB Output is correct
40 Correct 20 ms 10768 KB Output is correct
41 Correct 18 ms 10768 KB Output is correct
42 Correct 19 ms 10768 KB Output is correct
43 Correct 24 ms 10768 KB Output is correct
44 Correct 20 ms 10768 KB Output is correct
45 Correct 19 ms 10768 KB Output is correct
46 Correct 22 ms 10768 KB Output is correct
47 Correct 27 ms 10768 KB Output is correct
48 Correct 21 ms 10768 KB Output is correct
49 Correct 19 ms 10768 KB Output is correct
50 Correct 19 ms 10768 KB Output is correct
51 Correct 21 ms 10768 KB Output is correct
52 Correct 24 ms 10768 KB Output is correct
53 Correct 24 ms 10768 KB Output is correct
54 Correct 12 ms 10768 KB Output is correct
55 Correct 12 ms 10768 KB Output is correct
56 Correct 12 ms 10768 KB Output is correct
57 Correct 16 ms 10768 KB Output is correct
58 Correct 17 ms 10768 KB Output is correct
59 Correct 1883 ms 10768 KB Output is correct
60 Correct 1875 ms 10768 KB Output is correct
61 Correct 1922 ms 10768 KB Output is correct
62 Correct 1961 ms 10768 KB Output is correct
63 Execution timed out 2071 ms 10768 KB Time limit exceeded
64 Halted 0 ms 0 KB -