답안 #109349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109349 2019-05-06T08:36:14 Z b2563125 Boat (APIO16_boat) C++14
9 / 100
2000 ms 12800 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;
int ref(int &a) {
	a = a % pr;
	a += pr;
	a = a % pr;
	return a;
}
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) {
	ref(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);
			com[i].push_back(ba);
		}
	}
	V<vel> dp0(2,vel(sz-1, 0));
	V<V<vel>> dp1(2, V<vel>(sz-1,vel(n)));
	rep(i, n) {
		int now = i % 2;
		int nex = (i + 1) % 2;
		dp0[nex] = dp0[now];
		dp1[nex] = dp1[now];
		int sum = 1;
		rep(j, a[i]) {
			sum += dp0[now][j]; ref(sum);
		}
		for (int j = a[i]; j < b[i]; j++) {
			pl(dp1[nex][j][0],sum);
			pl(dp0[nex][j], sum*gap[j]);
			rep(k, count[j] - 1) {
				pl(dp1[nex][j][k + 1], dp1[nex][j][k]);
				pl(dp0[nex][j], dp1[nex][j][k] * com[j][k + 1]);
			}
			sum += dp0[now][j];
		}
	}
	int ans = 0;
	rep(i, sz-1) {
		pl(ans,dp0[n % 2][i]);
	}
	cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 12288 KB Output is correct
2 Correct 218 ms 12408 KB Output is correct
3 Correct 223 ms 12408 KB Output is correct
4 Correct 221 ms 12288 KB Output is correct
5 Correct 208 ms 12260 KB Output is correct
6 Correct 228 ms 12408 KB Output is correct
7 Correct 220 ms 12288 KB Output is correct
8 Correct 243 ms 12288 KB Output is correct
9 Correct 236 ms 12344 KB Output is correct
10 Correct 210 ms 12408 KB Output is correct
11 Correct 231 ms 12380 KB Output is correct
12 Correct 226 ms 12380 KB Output is correct
13 Correct 236 ms 12308 KB Output is correct
14 Correct 232 ms 12348 KB Output is correct
15 Correct 238 ms 12408 KB Output is correct
16 Correct 37 ms 2432 KB Output is correct
17 Correct 42 ms 2688 KB Output is correct
18 Correct 35 ms 2552 KB Output is correct
19 Correct 39 ms 2560 KB Output is correct
20 Correct 39 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 12288 KB Output is correct
2 Correct 218 ms 12408 KB Output is correct
3 Correct 223 ms 12408 KB Output is correct
4 Correct 221 ms 12288 KB Output is correct
5 Correct 208 ms 12260 KB Output is correct
6 Correct 228 ms 12408 KB Output is correct
7 Correct 220 ms 12288 KB Output is correct
8 Correct 243 ms 12288 KB Output is correct
9 Correct 236 ms 12344 KB Output is correct
10 Correct 210 ms 12408 KB Output is correct
11 Correct 231 ms 12380 KB Output is correct
12 Correct 226 ms 12380 KB Output is correct
13 Correct 236 ms 12308 KB Output is correct
14 Correct 232 ms 12348 KB Output is correct
15 Correct 238 ms 12408 KB Output is correct
16 Correct 37 ms 2432 KB Output is correct
17 Correct 42 ms 2688 KB Output is correct
18 Correct 35 ms 2552 KB Output is correct
19 Correct 39 ms 2560 KB Output is correct
20 Correct 39 ms 2560 KB Output is correct
21 Execution timed out 2050 ms 12800 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 12288 KB Output is correct
2 Correct 218 ms 12408 KB Output is correct
3 Correct 223 ms 12408 KB Output is correct
4 Correct 221 ms 12288 KB Output is correct
5 Correct 208 ms 12260 KB Output is correct
6 Correct 228 ms 12408 KB Output is correct
7 Correct 220 ms 12288 KB Output is correct
8 Correct 243 ms 12288 KB Output is correct
9 Correct 236 ms 12344 KB Output is correct
10 Correct 210 ms 12408 KB Output is correct
11 Correct 231 ms 12380 KB Output is correct
12 Correct 226 ms 12380 KB Output is correct
13 Correct 236 ms 12308 KB Output is correct
14 Correct 232 ms 12348 KB Output is correct
15 Correct 238 ms 12408 KB Output is correct
16 Correct 37 ms 2432 KB Output is correct
17 Correct 42 ms 2688 KB Output is correct
18 Correct 35 ms 2552 KB Output is correct
19 Correct 39 ms 2560 KB Output is correct
20 Correct 39 ms 2560 KB Output is correct
21 Execution timed out 2050 ms 12800 KB Time limit exceeded
22 Halted 0 ms 0 KB -