답안 #109373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109373 2019-05-06T09:53:44 Z b2563125 Boat (APIO16_boat) C++14
100 / 100
1903 ms 7112 KB
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
#define vel vector<long long>
#define V vector
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
int pr = 1000000007;
void uni(vel &a) {
	vel ans(1, a[0]);
	int n = a.size();
	rep(i, n - 1) { if (a[i + 1] != a[i]) { ans.push_back(a[i + 1]); } }
	a = ans;
}
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int back = rui(a, n / 2);
	back *= back; back %= pr;
	if (n % 2 == 0) { return back; }
	return (back*a) % pr;
}
int inv(int a) {
	return rui(a, pr - 2);
}
signed main() {
	ll n; cin >> n;
	vel a(n);
	vel b(n);
	vel all_time(1, 0);
	rep(i, n) {
		cin >> a[i] >> b[i]; b[i]++;
		all_time.push_back(a[i]);
		all_time.push_back(b[i]);
	}
	sort(all_time.begin(), all_time.end());
	uni(all_time);
	int sz = all_time.size();
	vel gap(sz - 1);
	rep(i, sz - 1) { gap[i] = all_time[i + 1] - all_time[i]; }
	vel count(sz - 1);
	rep(i, n) {
		a[i] = lower_bound(all_time.begin(), all_time.end(), a[i]) - all_time.begin();
		b[i] = lower_bound(all_time.begin(), all_time.end(), b[i]) - all_time.begin();
		rep(j, b[i] - a[i]) {
			count[a[i] + j]++;
		}
	}
	V<vel> com(sz - 1);
	rep(i, sz - 1) {
		int ba = 1;
		rep(j, count[i]) {
			ba *= gap[i] - j; ba %= pr;
			ba *= inv(j + 1); ba %= pr;
			com[i].push_back(ba);
		}
	}
	V<V<vel>> dp1(2);
	rep(i, 2) {
		rep(j, sz - 1) {
			dp1[i].push_back(vel(count[j], 0));
		}
	}
	vel now_count(sz - 1, 0);
	rep(i, n) {
		int now = i % 2;
		int nex = (i + 1) % 2;
		dp1[nex] = dp1[now];
		int sum = 1;
		rep(j, a[i]) {
			rep(k, now_count[j]) {
				sum += dp1[now][j][k] * com[j][k];
				sum %= pr;
			}
		}
		for (int j = a[i]; j < b[i]; j++) {
			dp1[nex][j][0] += sum; dp1[nex][j][0] %= pr;
			rep(k, now_count[j]) {
				dp1[nex][j][k + 1] += dp1[now][j][k]; dp1[nex][j][k + 1] %= pr;
				sum += dp1[now][j][k] * com[j][k];
				sum %= pr;
			}
			now_count[j]++;
		}
	}
	ll ans = 0;
	rep(i, sz - 1) {
		rep(k, count[i]) {
			ans += dp1[n % 2][i][k] * com[i][k];
			ans %= pr;
		}
	}
	cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 10 ms 512 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 12 ms 512 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 10 ms 512 KB Output is correct
10 Correct 9 ms 512 KB Output is correct
11 Correct 9 ms 512 KB Output is correct
12 Correct 9 ms 512 KB Output is correct
13 Correct 10 ms 512 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 9 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 10 ms 512 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 12 ms 512 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 10 ms 512 KB Output is correct
10 Correct 9 ms 512 KB Output is correct
11 Correct 9 ms 512 KB Output is correct
12 Correct 9 ms 512 KB Output is correct
13 Correct 10 ms 512 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 9 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 823 ms 4496 KB Output is correct
22 Correct 860 ms 4604 KB Output is correct
23 Correct 706 ms 4328 KB Output is correct
24 Correct 688 ms 4548 KB Output is correct
25 Correct 773 ms 4600 KB Output is correct
26 Correct 1332 ms 6264 KB Output is correct
27 Correct 1374 ms 6392 KB Output is correct
28 Correct 1505 ms 6264 KB Output is correct
29 Correct 1429 ms 6136 KB Output is correct
30 Correct 14 ms 512 KB Output is correct
31 Correct 17 ms 512 KB Output is correct
32 Correct 14 ms 512 KB Output is correct
33 Correct 18 ms 512 KB Output is correct
34 Correct 13 ms 512 KB Output is correct
35 Correct 13 ms 512 KB Output is correct
36 Correct 12 ms 512 KB Output is correct
37 Correct 12 ms 512 KB Output is correct
38 Correct 13 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 14 ms 512 KB Output is correct
4 Correct 15 ms 512 KB Output is correct
5 Correct 15 ms 512 KB Output is correct
6 Correct 22 ms 640 KB Output is correct
7 Correct 22 ms 640 KB Output is correct
8 Correct 24 ms 768 KB Output is correct
9 Correct 22 ms 612 KB Output is correct
10 Correct 27 ms 640 KB Output is correct
11 Correct 16 ms 512 KB Output is correct
12 Correct 15 ms 512 KB Output is correct
13 Correct 16 ms 512 KB Output is correct
14 Correct 14 ms 512 KB Output is correct
15 Correct 15 ms 512 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 9 ms 384 KB Output is correct
18 Correct 10 ms 512 KB Output is correct
19 Correct 10 ms 512 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 10 ms 512 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 12 ms 512 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 10 ms 512 KB Output is correct
10 Correct 9 ms 512 KB Output is correct
11 Correct 9 ms 512 KB Output is correct
12 Correct 9 ms 512 KB Output is correct
13 Correct 10 ms 512 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 9 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 823 ms 4496 KB Output is correct
22 Correct 860 ms 4604 KB Output is correct
23 Correct 706 ms 4328 KB Output is correct
24 Correct 688 ms 4548 KB Output is correct
25 Correct 773 ms 4600 KB Output is correct
26 Correct 1332 ms 6264 KB Output is correct
27 Correct 1374 ms 6392 KB Output is correct
28 Correct 1505 ms 6264 KB Output is correct
29 Correct 1429 ms 6136 KB Output is correct
30 Correct 14 ms 512 KB Output is correct
31 Correct 17 ms 512 KB Output is correct
32 Correct 14 ms 512 KB Output is correct
33 Correct 18 ms 512 KB Output is correct
34 Correct 13 ms 512 KB Output is correct
35 Correct 13 ms 512 KB Output is correct
36 Correct 12 ms 512 KB Output is correct
37 Correct 12 ms 512 KB Output is correct
38 Correct 13 ms 512 KB Output is correct
39 Correct 16 ms 512 KB Output is correct
40 Correct 11 ms 512 KB Output is correct
41 Correct 14 ms 512 KB Output is correct
42 Correct 15 ms 512 KB Output is correct
43 Correct 15 ms 512 KB Output is correct
44 Correct 22 ms 640 KB Output is correct
45 Correct 22 ms 640 KB Output is correct
46 Correct 24 ms 768 KB Output is correct
47 Correct 22 ms 612 KB Output is correct
48 Correct 27 ms 640 KB Output is correct
49 Correct 16 ms 512 KB Output is correct
50 Correct 15 ms 512 KB Output is correct
51 Correct 16 ms 512 KB Output is correct
52 Correct 14 ms 512 KB Output is correct
53 Correct 15 ms 512 KB Output is correct
54 Correct 9 ms 384 KB Output is correct
55 Correct 9 ms 384 KB Output is correct
56 Correct 10 ms 512 KB Output is correct
57 Correct 10 ms 512 KB Output is correct
58 Correct 10 ms 512 KB Output is correct
59 Correct 913 ms 4988 KB Output is correct
60 Correct 804 ms 4600 KB Output is correct
61 Correct 796 ms 4600 KB Output is correct
62 Correct 979 ms 5236 KB Output is correct
63 Correct 889 ms 4856 KB Output is correct
64 Correct 1903 ms 7032 KB Output is correct
65 Correct 1788 ms 7032 KB Output is correct
66 Correct 1817 ms 7112 KB Output is correct
67 Correct 1818 ms 7032 KB Output is correct
68 Correct 1759 ms 7036 KB Output is correct
69 Correct 973 ms 4604 KB Output is correct
70 Correct 1055 ms 4604 KB Output is correct
71 Correct 1057 ms 4728 KB Output is correct
72 Correct 1089 ms 4728 KB Output is correct
73 Correct 1096 ms 4600 KB Output is correct
74 Correct 163 ms 1144 KB Output is correct
75 Correct 160 ms 1148 KB Output is correct
76 Correct 174 ms 1144 KB Output is correct
77 Correct 159 ms 1144 KB Output is correct
78 Correct 172 ms 1280 KB Output is correct