답안 #385715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
385715 2021-04-04T19:22:18 Z idontreallyknow Boat (APIO16_boat) C++17
100 / 100
1459 ms 50668 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";};
template<class A, class B> ostream& operator<<(ostream &cout, const pair<A,B> &x) {return cout << "(" <<x.first << ", " << x.second << ")";};
template <class T> void pv(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) cerr << *i << " "; cerr << "]\n";}
void _print() {cerr << "]\n";}
template <class T, class... V> void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define fi first
#define se second
#define SZ(x) (int)((x).size())
#define pii pair<int,int>
template<int modd> struct modint {
	static const int mod = modd;
	int v; explicit operator int() const { return v;}
	modint() : v(0) {}
	modint(ll x) : v(int(x%mod)) {if (v < 0) v += mod;}
	friend bool operator==(const modint& a, const modint& b) {return a.v == b.v;}
	friend bool operator!=(const modint& a, const modint& b) {return a.v != b.v;}
	friend bool operator<(const modint& a, const modint& b) {return a.v < b.v;}
	modint& operator+=(const modint& a) {if ((v += a.v) >= mod) v -= mod; return *this;}
	modint& operator-=(const modint& a) {if ((v -= a.v) < 0) v += mod; return *this;}
	modint& operator*=(const modint& a) {v = int((ll)v*a.v%mod); return *this;}
	modint& operator/=(const modint& a) {return (*this) *= inv(a);}
	friend modint pow(modint a, ll p) {modint ret = 1; for (; p; p /= 2, a *= a){if (p&1) ret *= a;} return ret;}
	friend modint inv(const modint& a) {return pow(a,mod-2);}
	modint operator-() const {return modint(-v);}
	modint& operator++() {return *this += 1;}
	modint& operator--() {return *this -= 1;}
	friend modint operator+(modint a, const modint& b) {return a += b;}
	friend modint operator-(modint a, const modint& b) {return a -= b;}
	friend modint operator*(modint a, const modint& b) {return a *= b;}
	friend modint operator/(modint a, const modint& b) {return a /= b;}
	friend ostream& operator<<(ostream& out, modint a) {return out << a.v;}
	friend istream& operator>>(istream& in, modint& a) {ll b; in >> b; a.v = b; return in;}
};
using mint = modint<1000000007>;
const int mx = 505;
int a[mx], b[mx], n;
mint choose[5*mx][5*mx], dp[5*mx][5*mx];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	map<int,int> pts;
	for (int q = 1; q <= n; q++) {
		cin >> a[q] >> b[q];
		pts[a[q]] = 1;
		pts[b[q]] = 1;
	}
	auto it = pts.begin();
	vector<pii> inter = {{0,0}};
	while (it != pts.end()) {
		inter.emplace_back(it->fi, it->fi);
		auto it1 = it;
		it1++;
		if (it1 != pts.end()) {
			if (it1->fi - 1 >= it->fi + 1) {
				inter.emplace_back(it->fi + 1, it1->fi - 1);
			}
		}
		it++;
	}
	int m = SZ(inter);
	for (int q = 0; q < m; q++) {
		int x = inter[q].se-inter[q].fi+1;
		for (int w = 0; w <= n; w++) {
			if (w+2 > x+w) continue;
			mint num = 1, den = 1;
			for (int e = 1; e <= w+2; e++) {
				num *= (x+w+1-e);
				den *= e;
			}
			choose[q][w] = num*inv(den);
		}
	}
	for (int q = 0; q < 5*mx; q++) dp[0][q] = 1;
	for (int q = 1; q <= n; q++) {
		dp[q][0] = 1;
		for (int w = 1; w < m; w++) {
			if (inter[w].fi < a[q] || inter[w].se > b[q]) continue;
			dp[q][w] += dp[q-1][w-1]*(inter[w].se-inter[w].fi+1);
			int ctr = 0;
			for (int e = q-1; e > 0; e--) {
				if (inter[w].fi >= a[e] && inter[w].se <= b[e]) {
					dp[q][w] += dp[e-1][w-1]*choose[w][ctr];
					ctr++;
				}
			}
		}
		for (int w = 2; w < m; w++) dp[q][w] += dp[q][w-1];
		for (int w = 1; w < m; w++) dp[q][w] += dp[q-1][w];
	}
	cout << dp[n][m-1]-1 << "\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 464 ms 50284 KB Output is correct
2 Correct 475 ms 50412 KB Output is correct
3 Correct 468 ms 50364 KB Output is correct
4 Correct 468 ms 50412 KB Output is correct
5 Correct 486 ms 50412 KB Output is correct
6 Correct 466 ms 50284 KB Output is correct
7 Correct 470 ms 50412 KB Output is correct
8 Correct 481 ms 50412 KB Output is correct
9 Correct 463 ms 50412 KB Output is correct
10 Correct 469 ms 50364 KB Output is correct
11 Correct 466 ms 50284 KB Output is correct
12 Correct 464 ms 50412 KB Output is correct
13 Correct 476 ms 50364 KB Output is correct
14 Correct 464 ms 50284 KB Output is correct
15 Correct 475 ms 50540 KB Output is correct
16 Correct 106 ms 50284 KB Output is correct
17 Correct 120 ms 50412 KB Output is correct
18 Correct 110 ms 50284 KB Output is correct
19 Correct 114 ms 50284 KB Output is correct
20 Correct 111 ms 50284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 464 ms 50284 KB Output is correct
2 Correct 475 ms 50412 KB Output is correct
3 Correct 468 ms 50364 KB Output is correct
4 Correct 468 ms 50412 KB Output is correct
5 Correct 486 ms 50412 KB Output is correct
6 Correct 466 ms 50284 KB Output is correct
7 Correct 470 ms 50412 KB Output is correct
8 Correct 481 ms 50412 KB Output is correct
9 Correct 463 ms 50412 KB Output is correct
10 Correct 469 ms 50364 KB Output is correct
11 Correct 466 ms 50284 KB Output is correct
12 Correct 464 ms 50412 KB Output is correct
13 Correct 476 ms 50364 KB Output is correct
14 Correct 464 ms 50284 KB Output is correct
15 Correct 475 ms 50540 KB Output is correct
16 Correct 106 ms 50284 KB Output is correct
17 Correct 120 ms 50412 KB Output is correct
18 Correct 110 ms 50284 KB Output is correct
19 Correct 114 ms 50284 KB Output is correct
20 Correct 111 ms 50284 KB Output is correct
21 Correct 828 ms 50412 KB Output is correct
22 Correct 815 ms 50284 KB Output is correct
23 Correct 787 ms 50412 KB Output is correct
24 Correct 846 ms 50540 KB Output is correct
25 Correct 837 ms 50668 KB Output is correct
26 Correct 912 ms 50284 KB Output is correct
27 Correct 921 ms 50412 KB Output is correct
28 Correct 931 ms 50284 KB Output is correct
29 Correct 917 ms 50392 KB Output is correct
30 Correct 776 ms 50284 KB Output is correct
31 Correct 773 ms 50400 KB Output is correct
32 Correct 773 ms 50412 KB Output is correct
33 Correct 789 ms 50412 KB Output is correct
34 Correct 783 ms 50412 KB Output is correct
35 Correct 474 ms 50412 KB Output is correct
36 Correct 465 ms 50284 KB Output is correct
37 Correct 468 ms 50412 KB Output is correct
38 Correct 475 ms 50412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 50284 KB Output is correct
2 Correct 43 ms 50284 KB Output is correct
3 Correct 43 ms 50284 KB Output is correct
4 Correct 43 ms 50284 KB Output is correct
5 Correct 43 ms 50284 KB Output is correct
6 Correct 48 ms 50284 KB Output is correct
7 Correct 45 ms 50284 KB Output is correct
8 Correct 45 ms 50284 KB Output is correct
9 Correct 47 ms 50412 KB Output is correct
10 Correct 45 ms 50284 KB Output is correct
11 Correct 44 ms 50412 KB Output is correct
12 Correct 42 ms 50284 KB Output is correct
13 Correct 43 ms 50304 KB Output is correct
14 Correct 44 ms 50412 KB Output is correct
15 Correct 44 ms 50284 KB Output is correct
16 Correct 36 ms 50284 KB Output is correct
17 Correct 36 ms 50284 KB Output is correct
18 Correct 36 ms 50284 KB Output is correct
19 Correct 36 ms 50284 KB Output is correct
20 Correct 37 ms 50284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 464 ms 50284 KB Output is correct
2 Correct 475 ms 50412 KB Output is correct
3 Correct 468 ms 50364 KB Output is correct
4 Correct 468 ms 50412 KB Output is correct
5 Correct 486 ms 50412 KB Output is correct
6 Correct 466 ms 50284 KB Output is correct
7 Correct 470 ms 50412 KB Output is correct
8 Correct 481 ms 50412 KB Output is correct
9 Correct 463 ms 50412 KB Output is correct
10 Correct 469 ms 50364 KB Output is correct
11 Correct 466 ms 50284 KB Output is correct
12 Correct 464 ms 50412 KB Output is correct
13 Correct 476 ms 50364 KB Output is correct
14 Correct 464 ms 50284 KB Output is correct
15 Correct 475 ms 50540 KB Output is correct
16 Correct 106 ms 50284 KB Output is correct
17 Correct 120 ms 50412 KB Output is correct
18 Correct 110 ms 50284 KB Output is correct
19 Correct 114 ms 50284 KB Output is correct
20 Correct 111 ms 50284 KB Output is correct
21 Correct 828 ms 50412 KB Output is correct
22 Correct 815 ms 50284 KB Output is correct
23 Correct 787 ms 50412 KB Output is correct
24 Correct 846 ms 50540 KB Output is correct
25 Correct 837 ms 50668 KB Output is correct
26 Correct 912 ms 50284 KB Output is correct
27 Correct 921 ms 50412 KB Output is correct
28 Correct 931 ms 50284 KB Output is correct
29 Correct 917 ms 50392 KB Output is correct
30 Correct 776 ms 50284 KB Output is correct
31 Correct 773 ms 50400 KB Output is correct
32 Correct 773 ms 50412 KB Output is correct
33 Correct 789 ms 50412 KB Output is correct
34 Correct 783 ms 50412 KB Output is correct
35 Correct 474 ms 50412 KB Output is correct
36 Correct 465 ms 50284 KB Output is correct
37 Correct 468 ms 50412 KB Output is correct
38 Correct 475 ms 50412 KB Output is correct
39 Correct 48 ms 50284 KB Output is correct
40 Correct 43 ms 50284 KB Output is correct
41 Correct 43 ms 50284 KB Output is correct
42 Correct 43 ms 50284 KB Output is correct
43 Correct 43 ms 50284 KB Output is correct
44 Correct 48 ms 50284 KB Output is correct
45 Correct 45 ms 50284 KB Output is correct
46 Correct 45 ms 50284 KB Output is correct
47 Correct 47 ms 50412 KB Output is correct
48 Correct 45 ms 50284 KB Output is correct
49 Correct 44 ms 50412 KB Output is correct
50 Correct 42 ms 50284 KB Output is correct
51 Correct 43 ms 50304 KB Output is correct
52 Correct 44 ms 50412 KB Output is correct
53 Correct 44 ms 50284 KB Output is correct
54 Correct 36 ms 50284 KB Output is correct
55 Correct 36 ms 50284 KB Output is correct
56 Correct 36 ms 50284 KB Output is correct
57 Correct 36 ms 50284 KB Output is correct
58 Correct 37 ms 50284 KB Output is correct
59 Correct 1205 ms 50284 KB Output is correct
60 Correct 1201 ms 50412 KB Output is correct
61 Correct 1170 ms 50404 KB Output is correct
62 Correct 1216 ms 50404 KB Output is correct
63 Correct 1193 ms 50412 KB Output is correct
64 Correct 1447 ms 50404 KB Output is correct
65 Correct 1459 ms 50404 KB Output is correct
66 Correct 1441 ms 50404 KB Output is correct
67 Correct 1433 ms 50404 KB Output is correct
68 Correct 1440 ms 50404 KB Output is correct
69 Correct 1122 ms 50540 KB Output is correct
70 Correct 1125 ms 50412 KB Output is correct
71 Correct 1116 ms 50404 KB Output is correct
72 Correct 1135 ms 50412 KB Output is correct
73 Correct 1138 ms 50412 KB Output is correct
74 Correct 154 ms 50284 KB Output is correct
75 Correct 152 ms 50320 KB Output is correct
76 Correct 159 ms 50284 KB Output is correct
77 Correct 155 ms 50284 KB Output is correct
78 Correct 154 ms 50332 KB Output is correct