답안 #109369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109369 2019-05-06T09:46:56 Z b2563125 Boat (APIO16_boat) C++14
36 / 100
2000 ms 13172 KB
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define int __int128
#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, 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];
				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;
			}
			sum += dp1[now][j][now_count[j]] * com[j][now_count[j]];
			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 206 ms 12288 KB Output is correct
2 Correct 225 ms 12288 KB Output is correct
3 Correct 198 ms 12288 KB Output is correct
4 Correct 219 ms 12408 KB Output is correct
5 Correct 199 ms 12408 KB Output is correct
6 Correct 204 ms 12288 KB Output is correct
7 Correct 212 ms 12408 KB Output is correct
8 Correct 234 ms 12408 KB Output is correct
9 Correct 180 ms 12288 KB Output is correct
10 Correct 195 ms 12328 KB Output is correct
11 Correct 200 ms 12288 KB Output is correct
12 Correct 202 ms 12408 KB Output is correct
13 Correct 174 ms 12328 KB Output is correct
14 Correct 184 ms 12384 KB Output is correct
15 Correct 196 ms 12292 KB Output is correct
16 Correct 36 ms 2560 KB Output is correct
17 Correct 38 ms 2688 KB Output is correct
18 Correct 39 ms 2560 KB Output is correct
19 Correct 41 ms 2808 KB Output is correct
20 Correct 38 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 12288 KB Output is correct
2 Correct 225 ms 12288 KB Output is correct
3 Correct 198 ms 12288 KB Output is correct
4 Correct 219 ms 12408 KB Output is correct
5 Correct 199 ms 12408 KB Output is correct
6 Correct 204 ms 12288 KB Output is correct
7 Correct 212 ms 12408 KB Output is correct
8 Correct 234 ms 12408 KB Output is correct
9 Correct 180 ms 12288 KB Output is correct
10 Correct 195 ms 12328 KB Output is correct
11 Correct 200 ms 12288 KB Output is correct
12 Correct 202 ms 12408 KB Output is correct
13 Correct 174 ms 12328 KB Output is correct
14 Correct 184 ms 12384 KB Output is correct
15 Correct 196 ms 12292 KB Output is correct
16 Correct 36 ms 2560 KB Output is correct
17 Correct 38 ms 2688 KB Output is correct
18 Correct 39 ms 2560 KB Output is correct
19 Correct 41 ms 2808 KB Output is correct
20 Correct 38 ms 2560 KB Output is correct
21 Correct 1433 ms 12892 KB Output is correct
22 Correct 1330 ms 13132 KB Output is correct
23 Correct 1230 ms 12640 KB Output is correct
24 Correct 1301 ms 12792 KB Output is correct
25 Correct 1425 ms 12792 KB Output is correct
26 Execution timed out 2041 ms 13172 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 948 KB Output is correct
2 Correct 15 ms 896 KB Output is correct
3 Correct 20 ms 896 KB Output is correct
4 Correct 24 ms 896 KB Output is correct
5 Correct 22 ms 896 KB Output is correct
6 Correct 31 ms 896 KB Output is correct
7 Correct 27 ms 896 KB Output is correct
8 Correct 31 ms 896 KB Output is correct
9 Correct 28 ms 1024 KB Output is correct
10 Correct 38 ms 1024 KB Output is correct
11 Correct 25 ms 896 KB Output is correct
12 Correct 22 ms 896 KB Output is correct
13 Correct 24 ms 896 KB Output is correct
14 Correct 20 ms 896 KB Output is correct
15 Correct 24 ms 1144 KB Output is correct
16 Correct 14 ms 640 KB Output is correct
17 Correct 13 ms 640 KB Output is correct
18 Correct 12 ms 640 KB Output is correct
19 Correct 11 ms 640 KB Output is correct
20 Correct 12 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 12288 KB Output is correct
2 Correct 225 ms 12288 KB Output is correct
3 Correct 198 ms 12288 KB Output is correct
4 Correct 219 ms 12408 KB Output is correct
5 Correct 199 ms 12408 KB Output is correct
6 Correct 204 ms 12288 KB Output is correct
7 Correct 212 ms 12408 KB Output is correct
8 Correct 234 ms 12408 KB Output is correct
9 Correct 180 ms 12288 KB Output is correct
10 Correct 195 ms 12328 KB Output is correct
11 Correct 200 ms 12288 KB Output is correct
12 Correct 202 ms 12408 KB Output is correct
13 Correct 174 ms 12328 KB Output is correct
14 Correct 184 ms 12384 KB Output is correct
15 Correct 196 ms 12292 KB Output is correct
16 Correct 36 ms 2560 KB Output is correct
17 Correct 38 ms 2688 KB Output is correct
18 Correct 39 ms 2560 KB Output is correct
19 Correct 41 ms 2808 KB Output is correct
20 Correct 38 ms 2560 KB Output is correct
21 Correct 1433 ms 12892 KB Output is correct
22 Correct 1330 ms 13132 KB Output is correct
23 Correct 1230 ms 12640 KB Output is correct
24 Correct 1301 ms 12792 KB Output is correct
25 Correct 1425 ms 12792 KB Output is correct
26 Execution timed out 2041 ms 13172 KB Time limit exceeded
27 Halted 0 ms 0 KB -