답안 #53347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53347 2018-06-29T14:57:21 Z junodeveloper Boat (APIO16_boat) C++11
100 / 100
1059 ms 11052 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);
			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;
			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 20 ms 9976 KB Output is correct
2 Correct 20 ms 9976 KB Output is correct
3 Correct 20 ms 10028 KB Output is correct
4 Correct 20 ms 10080 KB Output is correct
5 Correct 20 ms 10080 KB Output is correct
6 Correct 20 ms 10320 KB Output is correct
7 Correct 20 ms 10372 KB Output is correct
8 Correct 20 ms 10408 KB Output is correct
9 Correct 20 ms 10408 KB Output is correct
10 Correct 20 ms 10504 KB Output is correct
11 Correct 20 ms 10504 KB Output is correct
12 Correct 23 ms 10504 KB Output is correct
13 Correct 20 ms 10504 KB Output is correct
14 Correct 20 ms 10504 KB Output is correct
15 Correct 22 ms 10504 KB Output is correct
16 Correct 9 ms 10504 KB Output is correct
17 Correct 9 ms 10504 KB Output is correct
18 Correct 10 ms 10504 KB Output is correct
19 Correct 9 ms 10504 KB Output is correct
20 Correct 9 ms 10504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 9976 KB Output is correct
2 Correct 20 ms 9976 KB Output is correct
3 Correct 20 ms 10028 KB Output is correct
4 Correct 20 ms 10080 KB Output is correct
5 Correct 20 ms 10080 KB Output is correct
6 Correct 20 ms 10320 KB Output is correct
7 Correct 20 ms 10372 KB Output is correct
8 Correct 20 ms 10408 KB Output is correct
9 Correct 20 ms 10408 KB Output is correct
10 Correct 20 ms 10504 KB Output is correct
11 Correct 20 ms 10504 KB Output is correct
12 Correct 23 ms 10504 KB Output is correct
13 Correct 20 ms 10504 KB Output is correct
14 Correct 20 ms 10504 KB Output is correct
15 Correct 22 ms 10504 KB Output is correct
16 Correct 9 ms 10504 KB Output is correct
17 Correct 9 ms 10504 KB Output is correct
18 Correct 10 ms 10504 KB Output is correct
19 Correct 9 ms 10504 KB Output is correct
20 Correct 9 ms 10504 KB Output is correct
21 Correct 497 ms 10504 KB Output is correct
22 Correct 550 ms 10504 KB Output is correct
23 Correct 487 ms 10504 KB Output is correct
24 Correct 464 ms 10504 KB Output is correct
25 Correct 498 ms 10504 KB Output is correct
26 Correct 779 ms 10504 KB Output is correct
27 Correct 819 ms 10504 KB Output is correct
28 Correct 849 ms 10504 KB Output is correct
29 Correct 815 ms 10504 KB Output is correct
30 Correct 23 ms 10516 KB Output is correct
31 Correct 22 ms 10516 KB Output is correct
32 Correct 20 ms 10516 KB Output is correct
33 Correct 21 ms 10516 KB Output is correct
34 Correct 21 ms 10516 KB Output is correct
35 Correct 22 ms 10516 KB Output is correct
36 Correct 23 ms 10516 KB Output is correct
37 Correct 21 ms 10516 KB Output is correct
38 Correct 24 ms 10516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10516 KB Output is correct
2 Correct 7 ms 10516 KB Output is correct
3 Correct 8 ms 10516 KB Output is correct
4 Correct 9 ms 10516 KB Output is correct
5 Correct 10 ms 10516 KB Output is correct
6 Correct 11 ms 10516 KB Output is correct
7 Correct 12 ms 10516 KB Output is correct
8 Correct 14 ms 10516 KB Output is correct
9 Correct 12 ms 10516 KB Output is correct
10 Correct 11 ms 10516 KB Output is correct
11 Correct 8 ms 10516 KB Output is correct
12 Correct 8 ms 10516 KB Output is correct
13 Correct 8 ms 10516 KB Output is correct
14 Correct 7 ms 10516 KB Output is correct
15 Correct 9 ms 10516 KB Output is correct
16 Correct 7 ms 10516 KB Output is correct
17 Correct 8 ms 10516 KB Output is correct
18 Correct 6 ms 10516 KB Output is correct
19 Correct 6 ms 10516 KB Output is correct
20 Correct 6 ms 10516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 9976 KB Output is correct
2 Correct 20 ms 9976 KB Output is correct
3 Correct 20 ms 10028 KB Output is correct
4 Correct 20 ms 10080 KB Output is correct
5 Correct 20 ms 10080 KB Output is correct
6 Correct 20 ms 10320 KB Output is correct
7 Correct 20 ms 10372 KB Output is correct
8 Correct 20 ms 10408 KB Output is correct
9 Correct 20 ms 10408 KB Output is correct
10 Correct 20 ms 10504 KB Output is correct
11 Correct 20 ms 10504 KB Output is correct
12 Correct 23 ms 10504 KB Output is correct
13 Correct 20 ms 10504 KB Output is correct
14 Correct 20 ms 10504 KB Output is correct
15 Correct 22 ms 10504 KB Output is correct
16 Correct 9 ms 10504 KB Output is correct
17 Correct 9 ms 10504 KB Output is correct
18 Correct 10 ms 10504 KB Output is correct
19 Correct 9 ms 10504 KB Output is correct
20 Correct 9 ms 10504 KB Output is correct
21 Correct 497 ms 10504 KB Output is correct
22 Correct 550 ms 10504 KB Output is correct
23 Correct 487 ms 10504 KB Output is correct
24 Correct 464 ms 10504 KB Output is correct
25 Correct 498 ms 10504 KB Output is correct
26 Correct 779 ms 10504 KB Output is correct
27 Correct 819 ms 10504 KB Output is correct
28 Correct 849 ms 10504 KB Output is correct
29 Correct 815 ms 10504 KB Output is correct
30 Correct 23 ms 10516 KB Output is correct
31 Correct 22 ms 10516 KB Output is correct
32 Correct 20 ms 10516 KB Output is correct
33 Correct 21 ms 10516 KB Output is correct
34 Correct 21 ms 10516 KB Output is correct
35 Correct 22 ms 10516 KB Output is correct
36 Correct 23 ms 10516 KB Output is correct
37 Correct 21 ms 10516 KB Output is correct
38 Correct 24 ms 10516 KB Output is correct
39 Correct 9 ms 10516 KB Output is correct
40 Correct 7 ms 10516 KB Output is correct
41 Correct 8 ms 10516 KB Output is correct
42 Correct 9 ms 10516 KB Output is correct
43 Correct 10 ms 10516 KB Output is correct
44 Correct 11 ms 10516 KB Output is correct
45 Correct 12 ms 10516 KB Output is correct
46 Correct 14 ms 10516 KB Output is correct
47 Correct 12 ms 10516 KB Output is correct
48 Correct 11 ms 10516 KB Output is correct
49 Correct 8 ms 10516 KB Output is correct
50 Correct 8 ms 10516 KB Output is correct
51 Correct 8 ms 10516 KB Output is correct
52 Correct 7 ms 10516 KB Output is correct
53 Correct 9 ms 10516 KB Output is correct
54 Correct 7 ms 10516 KB Output is correct
55 Correct 8 ms 10516 KB Output is correct
56 Correct 6 ms 10516 KB Output is correct
57 Correct 6 ms 10516 KB Output is correct
58 Correct 6 ms 10516 KB Output is correct
59 Correct 621 ms 10516 KB Output is correct
60 Correct 555 ms 10568 KB Output is correct
61 Correct 493 ms 10604 KB Output is correct
62 Correct 532 ms 10604 KB Output is correct
63 Correct 593 ms 10720 KB Output is correct
64 Correct 928 ms 10756 KB Output is correct
65 Correct 1046 ms 10856 KB Output is correct
66 Correct 1059 ms 11052 KB Output is correct
67 Correct 946 ms 11052 KB Output is correct
68 Correct 978 ms 11052 KB Output is correct
69 Correct 394 ms 11052 KB Output is correct
70 Correct 435 ms 11052 KB Output is correct
71 Correct 427 ms 11052 KB Output is correct
72 Correct 421 ms 11052 KB Output is correct
73 Correct 435 ms 11052 KB Output is correct
74 Correct 96 ms 11052 KB Output is correct
75 Correct 93 ms 11052 KB Output is correct
76 Correct 97 ms 11052 KB Output is correct
77 Correct 97 ms 11052 KB Output is correct
78 Correct 104 ms 11052 KB Output is correct