답안 #109358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109358 2019-05-06T09:23:57 Z b2563125 Boat (APIO16_boat) C++14
58 / 100
2000 ms 14800 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 ref(int &a) {
	a = a % pr;
}
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; ref(back);
	if (n % 2 == 0) { return back; }
	return (back*a) % pr;
}
int inv(int a) {
	return rui(a, pr - 2);
}
void pl(int &a, int b) {
	a += b; ref(a);
}
signed main() {
	int 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; ref(ba);
			ba *= inv(j + 1); ref(ba);
			com[i].push_back(ba);
		}
	}
	V<V<vel>> dp1(2, V<vel>(sz-1,vel(n)));
	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];
				ref(sum);
			}
		}
		for (int j = a[i]; j < b[i]; j++) {
			pl(dp1[nex][j][0],sum);
			rep(k, now_count[j]) {
				pl(dp1[nex][j][k + 1], dp1[now][j][k]);
				sum += dp1[now][j][k] * com[j][k];
				ref(sum);
			}
			sum += dp1[now][j][now_count[j]] * com[j][now_count[j]];
			ref(sum);
			now_count[j]++;
		}
	}
	int ans = 0;
	rep(i, sz-1) {
		rep(k, count[i]) {
			ans += dp1[n%2][i][k] * com[i][k];
			ref(ans);
		}
	}
	cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 12288 KB Output is correct
2 Correct 217 ms 12408 KB Output is correct
3 Correct 217 ms 12288 KB Output is correct
4 Correct 191 ms 12288 KB Output is correct
5 Correct 207 ms 12288 KB Output is correct
6 Correct 205 ms 12408 KB Output is correct
7 Correct 196 ms 12380 KB Output is correct
8 Correct 197 ms 12288 KB Output is correct
9 Correct 210 ms 12408 KB Output is correct
10 Correct 248 ms 12288 KB Output is correct
11 Correct 222 ms 12288 KB Output is correct
12 Correct 178 ms 12288 KB Output is correct
13 Correct 219 ms 12288 KB Output is correct
14 Correct 210 ms 12288 KB Output is correct
15 Correct 220 ms 12292 KB Output is correct
16 Correct 37 ms 2432 KB Output is correct
17 Correct 38 ms 2644 KB Output is correct
18 Correct 38 ms 2432 KB Output is correct
19 Correct 40 ms 2680 KB Output is correct
20 Correct 38 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 12288 KB Output is correct
2 Correct 217 ms 12408 KB Output is correct
3 Correct 217 ms 12288 KB Output is correct
4 Correct 191 ms 12288 KB Output is correct
5 Correct 207 ms 12288 KB Output is correct
6 Correct 205 ms 12408 KB Output is correct
7 Correct 196 ms 12380 KB Output is correct
8 Correct 197 ms 12288 KB Output is correct
9 Correct 210 ms 12408 KB Output is correct
10 Correct 248 ms 12288 KB Output is correct
11 Correct 222 ms 12288 KB Output is correct
12 Correct 178 ms 12288 KB Output is correct
13 Correct 219 ms 12288 KB Output is correct
14 Correct 210 ms 12288 KB Output is correct
15 Correct 220 ms 12292 KB Output is correct
16 Correct 37 ms 2432 KB Output is correct
17 Correct 38 ms 2644 KB Output is correct
18 Correct 38 ms 2432 KB Output is correct
19 Correct 40 ms 2680 KB Output is correct
20 Correct 38 ms 2560 KB Output is correct
21 Correct 1175 ms 12840 KB Output is correct
22 Correct 1127 ms 13056 KB Output is correct
23 Correct 904 ms 12632 KB Output is correct
24 Correct 853 ms 12784 KB Output is correct
25 Correct 942 ms 12688 KB Output is correct
26 Correct 1901 ms 13152 KB Output is correct
27 Correct 1619 ms 13388 KB Output is correct
28 Correct 1748 ms 13140 KB Output is correct
29 Correct 1743 ms 13084 KB Output is correct
30 Correct 262 ms 12276 KB Output is correct
31 Correct 271 ms 12280 KB Output is correct
32 Correct 229 ms 12280 KB Output is correct
33 Correct 233 ms 12288 KB Output is correct
34 Correct 229 ms 12264 KB Output is correct
35 Correct 234 ms 12280 KB Output is correct
36 Correct 248 ms 12160 KB Output is correct
37 Correct 208 ms 12276 KB Output is correct
38 Correct 222 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 896 KB Output is correct
2 Correct 15 ms 896 KB Output is correct
3 Correct 15 ms 972 KB Output is correct
4 Correct 16 ms 944 KB Output is correct
5 Correct 17 ms 880 KB Output is correct
6 Correct 23 ms 876 KB Output is correct
7 Correct 26 ms 912 KB Output is correct
8 Correct 25 ms 976 KB Output is correct
9 Correct 25 ms 976 KB Output is correct
10 Correct 25 ms 1012 KB Output is correct
11 Correct 19 ms 936 KB Output is correct
12 Correct 16 ms 896 KB Output is correct
13 Correct 16 ms 896 KB Output is correct
14 Correct 20 ms 896 KB Output is correct
15 Correct 19 ms 896 KB Output is correct
16 Correct 11 ms 640 KB Output is correct
17 Correct 10 ms 640 KB Output is correct
18 Correct 10 ms 640 KB Output is correct
19 Correct 8 ms 640 KB Output is correct
20 Correct 10 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 12288 KB Output is correct
2 Correct 217 ms 12408 KB Output is correct
3 Correct 217 ms 12288 KB Output is correct
4 Correct 191 ms 12288 KB Output is correct
5 Correct 207 ms 12288 KB Output is correct
6 Correct 205 ms 12408 KB Output is correct
7 Correct 196 ms 12380 KB Output is correct
8 Correct 197 ms 12288 KB Output is correct
9 Correct 210 ms 12408 KB Output is correct
10 Correct 248 ms 12288 KB Output is correct
11 Correct 222 ms 12288 KB Output is correct
12 Correct 178 ms 12288 KB Output is correct
13 Correct 219 ms 12288 KB Output is correct
14 Correct 210 ms 12288 KB Output is correct
15 Correct 220 ms 12292 KB Output is correct
16 Correct 37 ms 2432 KB Output is correct
17 Correct 38 ms 2644 KB Output is correct
18 Correct 38 ms 2432 KB Output is correct
19 Correct 40 ms 2680 KB Output is correct
20 Correct 38 ms 2560 KB Output is correct
21 Correct 1175 ms 12840 KB Output is correct
22 Correct 1127 ms 13056 KB Output is correct
23 Correct 904 ms 12632 KB Output is correct
24 Correct 853 ms 12784 KB Output is correct
25 Correct 942 ms 12688 KB Output is correct
26 Correct 1901 ms 13152 KB Output is correct
27 Correct 1619 ms 13388 KB Output is correct
28 Correct 1748 ms 13140 KB Output is correct
29 Correct 1743 ms 13084 KB Output is correct
30 Correct 262 ms 12276 KB Output is correct
31 Correct 271 ms 12280 KB Output is correct
32 Correct 229 ms 12280 KB Output is correct
33 Correct 233 ms 12288 KB Output is correct
34 Correct 229 ms 12264 KB Output is correct
35 Correct 234 ms 12280 KB Output is correct
36 Correct 248 ms 12160 KB Output is correct
37 Correct 208 ms 12276 KB Output is correct
38 Correct 222 ms 12160 KB Output is correct
39 Correct 14 ms 896 KB Output is correct
40 Correct 15 ms 896 KB Output is correct
41 Correct 15 ms 972 KB Output is correct
42 Correct 16 ms 944 KB Output is correct
43 Correct 17 ms 880 KB Output is correct
44 Correct 23 ms 876 KB Output is correct
45 Correct 26 ms 912 KB Output is correct
46 Correct 25 ms 976 KB Output is correct
47 Correct 25 ms 976 KB Output is correct
48 Correct 25 ms 1012 KB Output is correct
49 Correct 19 ms 936 KB Output is correct
50 Correct 16 ms 896 KB Output is correct
51 Correct 16 ms 896 KB Output is correct
52 Correct 20 ms 896 KB Output is correct
53 Correct 19 ms 896 KB Output is correct
54 Correct 11 ms 640 KB Output is correct
55 Correct 10 ms 640 KB Output is correct
56 Correct 10 ms 640 KB Output is correct
57 Correct 8 ms 640 KB Output is correct
58 Correct 10 ms 640 KB Output is correct
59 Correct 1218 ms 14000 KB Output is correct
60 Correct 962 ms 13900 KB Output is correct
61 Correct 970 ms 13896 KB Output is correct
62 Correct 1287 ms 14264 KB Output is correct
63 Correct 1328 ms 13908 KB Output is correct
64 Execution timed out 2033 ms 14800 KB Time limit exceeded
65 Halted 0 ms 0 KB -