답안 #48643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48643 2018-05-17T15:04:59 Z nobik Boat (APIO16_boat) C++14
100 / 100
736 ms 8832 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())
#define ALL(a) (a).begin(), (a).end()

using ll = long long;
using K = long double;

const int inf = 1000*1000*1000 + 7;
const int mod = 1000*1000*1000 + 7;
const int N = 1005;

int power(int a, int n) {
	int result = 1;
	while (n > 0) {
		if (n % 2) {
			result = (1LL*result*a) % mod;
		}
		a = (1LL*a*a) % mod;
		n /= 2;
	}
	return result;
}

int inv(int a) {
	return power(a, mod-2);
}

void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

int n, m, l[N], r[N];
vector<int> d;
int f[N][N], g[N][N];

int inside(int id, int piece) {
	return l[id] <= d[piece] && r[id] >= d[piece+1];
}

int iv[N];
int c[N][N];
int cur[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n;
	REP(i, n) {
		cin >> l[i] >> r[i];
		++r[i];
		d.push_back(l[i]);
		d.push_back(r[i]);
	}
	sort(d.begin(), d.end());
	d.erase(unique(d.begin(), d.end()), d.end());
	m = SIZE(d)-1;
	f[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		iv[i] = inv(i);
	}
	REP(i, N) {
		c[i][0] = c[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			add(c[i][j], c[i-1][j-1]);
			add(c[i][j], c[i-1][j]);
		}
	}
	REP(w, m) {
		int len = d[w+1]-d[w];
		int first = len;
		for (int j = 0; j <= n; ++j) {
			first = 1LL*first*(len-j-1)%mod*iv[j+2] % mod;
			cur[j] = first;
		}
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= i; ++j) {
				add(g[i][w], 1LL*cur[j]*c[i][j] % mod);
			}
		}
	}
	REP(i, n) {
		REP(j, m+1) add(f[i+1][j], f[i][j]);
		REP(j, m) {
			add(f[i][j+1], f[i][j]);
			if (!inside(i, j)) continue;
			add(f[i+1][j+1], 1LL*f[i][j]*(d[j+1]-d[j]) % mod);
			int cnt = -1;
			for (int nxt = i+1; nxt < n; ++nxt) {
				if (!inside(nxt, j)) continue;
				++cnt;
				add(f[nxt+1][j+1], 1LL*f[i][j]*g[cnt][j] % mod);
			}
		}
	}
	int result = mod-1;
	REP(i, m+1) add(result, f[n][i]);
	cout << result << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 494 ms 8312 KB Output is correct
2 Correct 461 ms 8424 KB Output is correct
3 Correct 428 ms 8492 KB Output is correct
4 Correct 422 ms 8492 KB Output is correct
5 Correct 458 ms 8492 KB Output is correct
6 Correct 425 ms 8492 KB Output is correct
7 Correct 446 ms 8544 KB Output is correct
8 Correct 417 ms 8544 KB Output is correct
9 Correct 414 ms 8544 KB Output is correct
10 Correct 410 ms 8544 KB Output is correct
11 Correct 406 ms 8544 KB Output is correct
12 Correct 413 ms 8544 KB Output is correct
13 Correct 415 ms 8544 KB Output is correct
14 Correct 409 ms 8544 KB Output is correct
15 Correct 466 ms 8544 KB Output is correct
16 Correct 79 ms 8544 KB Output is correct
17 Correct 91 ms 8564 KB Output is correct
18 Correct 86 ms 8564 KB Output is correct
19 Correct 86 ms 8564 KB Output is correct
20 Correct 83 ms 8588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 494 ms 8312 KB Output is correct
2 Correct 461 ms 8424 KB Output is correct
3 Correct 428 ms 8492 KB Output is correct
4 Correct 422 ms 8492 KB Output is correct
5 Correct 458 ms 8492 KB Output is correct
6 Correct 425 ms 8492 KB Output is correct
7 Correct 446 ms 8544 KB Output is correct
8 Correct 417 ms 8544 KB Output is correct
9 Correct 414 ms 8544 KB Output is correct
10 Correct 410 ms 8544 KB Output is correct
11 Correct 406 ms 8544 KB Output is correct
12 Correct 413 ms 8544 KB Output is correct
13 Correct 415 ms 8544 KB Output is correct
14 Correct 409 ms 8544 KB Output is correct
15 Correct 466 ms 8544 KB Output is correct
16 Correct 79 ms 8544 KB Output is correct
17 Correct 91 ms 8564 KB Output is correct
18 Correct 86 ms 8564 KB Output is correct
19 Correct 86 ms 8564 KB Output is correct
20 Correct 83 ms 8588 KB Output is correct
21 Correct 533 ms 8588 KB Output is correct
22 Correct 527 ms 8588 KB Output is correct
23 Correct 532 ms 8588 KB Output is correct
24 Correct 573 ms 8588 KB Output is correct
25 Correct 584 ms 8588 KB Output is correct
26 Correct 642 ms 8700 KB Output is correct
27 Correct 646 ms 8700 KB Output is correct
28 Correct 698 ms 8700 KB Output is correct
29 Correct 656 ms 8700 KB Output is correct
30 Correct 440 ms 8700 KB Output is correct
31 Correct 410 ms 8700 KB Output is correct
32 Correct 542 ms 8700 KB Output is correct
33 Correct 417 ms 8700 KB Output is correct
34 Correct 436 ms 8700 KB Output is correct
35 Correct 425 ms 8700 KB Output is correct
36 Correct 384 ms 8700 KB Output is correct
37 Correct 426 ms 8700 KB Output is correct
38 Correct 544 ms 8700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8700 KB Output is correct
2 Correct 17 ms 8700 KB Output is correct
3 Correct 16 ms 8700 KB Output is correct
4 Correct 11 ms 8700 KB Output is correct
5 Correct 11 ms 8700 KB Output is correct
6 Correct 13 ms 8700 KB Output is correct
7 Correct 12 ms 8700 KB Output is correct
8 Correct 12 ms 8700 KB Output is correct
9 Correct 14 ms 8700 KB Output is correct
10 Correct 12 ms 8700 KB Output is correct
11 Correct 13 ms 8700 KB Output is correct
12 Correct 11 ms 8700 KB Output is correct
13 Correct 12 ms 8700 KB Output is correct
14 Correct 11 ms 8700 KB Output is correct
15 Correct 15 ms 8700 KB Output is correct
16 Correct 15 ms 8700 KB Output is correct
17 Correct 9 ms 8700 KB Output is correct
18 Correct 9 ms 8700 KB Output is correct
19 Correct 10 ms 8700 KB Output is correct
20 Correct 9 ms 8700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 494 ms 8312 KB Output is correct
2 Correct 461 ms 8424 KB Output is correct
3 Correct 428 ms 8492 KB Output is correct
4 Correct 422 ms 8492 KB Output is correct
5 Correct 458 ms 8492 KB Output is correct
6 Correct 425 ms 8492 KB Output is correct
7 Correct 446 ms 8544 KB Output is correct
8 Correct 417 ms 8544 KB Output is correct
9 Correct 414 ms 8544 KB Output is correct
10 Correct 410 ms 8544 KB Output is correct
11 Correct 406 ms 8544 KB Output is correct
12 Correct 413 ms 8544 KB Output is correct
13 Correct 415 ms 8544 KB Output is correct
14 Correct 409 ms 8544 KB Output is correct
15 Correct 466 ms 8544 KB Output is correct
16 Correct 79 ms 8544 KB Output is correct
17 Correct 91 ms 8564 KB Output is correct
18 Correct 86 ms 8564 KB Output is correct
19 Correct 86 ms 8564 KB Output is correct
20 Correct 83 ms 8588 KB Output is correct
21 Correct 533 ms 8588 KB Output is correct
22 Correct 527 ms 8588 KB Output is correct
23 Correct 532 ms 8588 KB Output is correct
24 Correct 573 ms 8588 KB Output is correct
25 Correct 584 ms 8588 KB Output is correct
26 Correct 642 ms 8700 KB Output is correct
27 Correct 646 ms 8700 KB Output is correct
28 Correct 698 ms 8700 KB Output is correct
29 Correct 656 ms 8700 KB Output is correct
30 Correct 440 ms 8700 KB Output is correct
31 Correct 410 ms 8700 KB Output is correct
32 Correct 542 ms 8700 KB Output is correct
33 Correct 417 ms 8700 KB Output is correct
34 Correct 436 ms 8700 KB Output is correct
35 Correct 425 ms 8700 KB Output is correct
36 Correct 384 ms 8700 KB Output is correct
37 Correct 426 ms 8700 KB Output is correct
38 Correct 544 ms 8700 KB Output is correct
39 Correct 11 ms 8700 KB Output is correct
40 Correct 17 ms 8700 KB Output is correct
41 Correct 16 ms 8700 KB Output is correct
42 Correct 11 ms 8700 KB Output is correct
43 Correct 11 ms 8700 KB Output is correct
44 Correct 13 ms 8700 KB Output is correct
45 Correct 12 ms 8700 KB Output is correct
46 Correct 12 ms 8700 KB Output is correct
47 Correct 14 ms 8700 KB Output is correct
48 Correct 12 ms 8700 KB Output is correct
49 Correct 13 ms 8700 KB Output is correct
50 Correct 11 ms 8700 KB Output is correct
51 Correct 12 ms 8700 KB Output is correct
52 Correct 11 ms 8700 KB Output is correct
53 Correct 15 ms 8700 KB Output is correct
54 Correct 15 ms 8700 KB Output is correct
55 Correct 9 ms 8700 KB Output is correct
56 Correct 9 ms 8700 KB Output is correct
57 Correct 10 ms 8700 KB Output is correct
58 Correct 9 ms 8700 KB Output is correct
59 Correct 650 ms 8700 KB Output is correct
60 Correct 731 ms 8700 KB Output is correct
61 Correct 605 ms 8700 KB Output is correct
62 Correct 583 ms 8700 KB Output is correct
63 Correct 561 ms 8700 KB Output is correct
64 Correct 705 ms 8700 KB Output is correct
65 Correct 706 ms 8700 KB Output is correct
66 Correct 736 ms 8700 KB Output is correct
67 Correct 734 ms 8700 KB Output is correct
68 Correct 733 ms 8704 KB Output is correct
69 Correct 528 ms 8704 KB Output is correct
70 Correct 535 ms 8704 KB Output is correct
71 Correct 521 ms 8772 KB Output is correct
72 Correct 519 ms 8784 KB Output is correct
73 Correct 557 ms 8784 KB Output is correct
74 Correct 114 ms 8784 KB Output is correct
75 Correct 140 ms 8784 KB Output is correct
76 Correct 117 ms 8832 KB Output is correct
77 Correct 120 ms 8832 KB Output is correct
78 Correct 114 ms 8832 KB Output is correct