답안 #53345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53345 2018-06-29T14:49:04 Z junodeveloper Boat (APIO16_boat) C++11
58 / 100
2000 ms 11236 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++) {
				int cnt = scnt[j][i] - scnt[j][k];
				dp[i][j] = (dp[i][j] + 1ll * dp2[k][j-1] * sum[j][cnt] % 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 1494 ms 10088 KB Output is correct
2 Correct 1618 ms 10228 KB Output is correct
3 Correct 1629 ms 10328 KB Output is correct
4 Correct 1506 ms 10328 KB Output is correct
5 Correct 1516 ms 10428 KB Output is correct
6 Correct 1519 ms 10788 KB Output is correct
7 Correct 1629 ms 10788 KB Output is correct
8 Correct 1554 ms 10788 KB Output is correct
9 Correct 1596 ms 10880 KB Output is correct
10 Correct 1553 ms 10880 KB Output is correct
11 Correct 1567 ms 10880 KB Output is correct
12 Correct 1510 ms 10880 KB Output is correct
13 Correct 1508 ms 10968 KB Output is correct
14 Correct 1549 ms 11064 KB Output is correct
15 Correct 1505 ms 11064 KB Output is correct
16 Correct 274 ms 11064 KB Output is correct
17 Correct 301 ms 11064 KB Output is correct
18 Correct 283 ms 11064 KB Output is correct
19 Correct 297 ms 11064 KB Output is correct
20 Correct 295 ms 11064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1494 ms 10088 KB Output is correct
2 Correct 1618 ms 10228 KB Output is correct
3 Correct 1629 ms 10328 KB Output is correct
4 Correct 1506 ms 10328 KB Output is correct
5 Correct 1516 ms 10428 KB Output is correct
6 Correct 1519 ms 10788 KB Output is correct
7 Correct 1629 ms 10788 KB Output is correct
8 Correct 1554 ms 10788 KB Output is correct
9 Correct 1596 ms 10880 KB Output is correct
10 Correct 1553 ms 10880 KB Output is correct
11 Correct 1567 ms 10880 KB Output is correct
12 Correct 1510 ms 10880 KB Output is correct
13 Correct 1508 ms 10968 KB Output is correct
14 Correct 1549 ms 11064 KB Output is correct
15 Correct 1505 ms 11064 KB Output is correct
16 Correct 274 ms 11064 KB Output is correct
17 Correct 301 ms 11064 KB Output is correct
18 Correct 283 ms 11064 KB Output is correct
19 Correct 297 ms 11064 KB Output is correct
20 Correct 295 ms 11064 KB Output is correct
21 Correct 1887 ms 11064 KB Output is correct
22 Correct 1950 ms 11064 KB Output is correct
23 Correct 1657 ms 11064 KB Output is correct
24 Correct 1767 ms 11064 KB Output is correct
25 Correct 1825 ms 11064 KB Output is correct
26 Correct 1751 ms 11064 KB Output is correct
27 Correct 1802 ms 11064 KB Output is correct
28 Correct 1736 ms 11064 KB Output is correct
29 Correct 1796 ms 11064 KB Output is correct
30 Correct 1725 ms 11092 KB Output is correct
31 Correct 1536 ms 11236 KB Output is correct
32 Correct 1467 ms 11236 KB Output is correct
33 Correct 1634 ms 11236 KB Output is correct
34 Correct 1603 ms 11236 KB Output is correct
35 Correct 1802 ms 11236 KB Output is correct
36 Correct 1576 ms 11236 KB Output is correct
37 Correct 1635 ms 11236 KB Output is correct
38 Correct 1530 ms 11236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11236 KB Output is correct
2 Correct 23 ms 11236 KB Output is correct
3 Correct 25 ms 11236 KB Output is correct
4 Correct 21 ms 11236 KB Output is correct
5 Correct 21 ms 11236 KB Output is correct
6 Correct 27 ms 11236 KB Output is correct
7 Correct 22 ms 11236 KB Output is correct
8 Correct 20 ms 11236 KB Output is correct
9 Correct 22 ms 11236 KB Output is correct
10 Correct 21 ms 11236 KB Output is correct
11 Correct 31 ms 11236 KB Output is correct
12 Correct 18 ms 11236 KB Output is correct
13 Correct 18 ms 11236 KB Output is correct
14 Correct 19 ms 11236 KB Output is correct
15 Correct 20 ms 11236 KB Output is correct
16 Correct 13 ms 11236 KB Output is correct
17 Correct 12 ms 11236 KB Output is correct
18 Correct 13 ms 11236 KB Output is correct
19 Correct 13 ms 11236 KB Output is correct
20 Correct 17 ms 11236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1494 ms 10088 KB Output is correct
2 Correct 1618 ms 10228 KB Output is correct
3 Correct 1629 ms 10328 KB Output is correct
4 Correct 1506 ms 10328 KB Output is correct
5 Correct 1516 ms 10428 KB Output is correct
6 Correct 1519 ms 10788 KB Output is correct
7 Correct 1629 ms 10788 KB Output is correct
8 Correct 1554 ms 10788 KB Output is correct
9 Correct 1596 ms 10880 KB Output is correct
10 Correct 1553 ms 10880 KB Output is correct
11 Correct 1567 ms 10880 KB Output is correct
12 Correct 1510 ms 10880 KB Output is correct
13 Correct 1508 ms 10968 KB Output is correct
14 Correct 1549 ms 11064 KB Output is correct
15 Correct 1505 ms 11064 KB Output is correct
16 Correct 274 ms 11064 KB Output is correct
17 Correct 301 ms 11064 KB Output is correct
18 Correct 283 ms 11064 KB Output is correct
19 Correct 297 ms 11064 KB Output is correct
20 Correct 295 ms 11064 KB Output is correct
21 Correct 1887 ms 11064 KB Output is correct
22 Correct 1950 ms 11064 KB Output is correct
23 Correct 1657 ms 11064 KB Output is correct
24 Correct 1767 ms 11064 KB Output is correct
25 Correct 1825 ms 11064 KB Output is correct
26 Correct 1751 ms 11064 KB Output is correct
27 Correct 1802 ms 11064 KB Output is correct
28 Correct 1736 ms 11064 KB Output is correct
29 Correct 1796 ms 11064 KB Output is correct
30 Correct 1725 ms 11092 KB Output is correct
31 Correct 1536 ms 11236 KB Output is correct
32 Correct 1467 ms 11236 KB Output is correct
33 Correct 1634 ms 11236 KB Output is correct
34 Correct 1603 ms 11236 KB Output is correct
35 Correct 1802 ms 11236 KB Output is correct
36 Correct 1576 ms 11236 KB Output is correct
37 Correct 1635 ms 11236 KB Output is correct
38 Correct 1530 ms 11236 KB Output is correct
39 Correct 30 ms 11236 KB Output is correct
40 Correct 23 ms 11236 KB Output is correct
41 Correct 25 ms 11236 KB Output is correct
42 Correct 21 ms 11236 KB Output is correct
43 Correct 21 ms 11236 KB Output is correct
44 Correct 27 ms 11236 KB Output is correct
45 Correct 22 ms 11236 KB Output is correct
46 Correct 20 ms 11236 KB Output is correct
47 Correct 22 ms 11236 KB Output is correct
48 Correct 21 ms 11236 KB Output is correct
49 Correct 31 ms 11236 KB Output is correct
50 Correct 18 ms 11236 KB Output is correct
51 Correct 18 ms 11236 KB Output is correct
52 Correct 19 ms 11236 KB Output is correct
53 Correct 20 ms 11236 KB Output is correct
54 Correct 13 ms 11236 KB Output is correct
55 Correct 12 ms 11236 KB Output is correct
56 Correct 13 ms 11236 KB Output is correct
57 Correct 13 ms 11236 KB Output is correct
58 Correct 17 ms 11236 KB Output is correct
59 Execution timed out 2069 ms 11236 KB Time limit exceeded
60 Halted 0 ms 0 KB -