답안 #554345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554345 2022-04-28T07:49:24 Z Keshi Boat (APIO16_boat) C++17
100 / 100
327 ms 13704 KB
//In the name of God
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll maxn = 1024;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()

ll pw(ll a, ll b){
	ll c = 1;
	while(b){
		if(b & 1) c = c * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return c;
}

int n, a[maxn], b[maxn];
ll pre[maxn][maxn];
vector<int> vec;
vector<pll> g[maxn];

int main(){
	fast_io;

	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		b[i]++;
		vec.pb(a[i]);
		vec.pb(b[i]);
	}
	vec.pb(0);
	sort(all(vec));
	vec.resize(unique(all(vec)) - vec.begin());
	for(int i = 0; i + 1 < Sz(vec); i++){
		g[i].pb({0, 0});
		int x = vec[i + 1] - vec[i] - 1;
		pre[i][0] = 1;
		for(int j = 1; j < maxn; j++){
			pre[i][j] = pre[i][j - 1] * (x + j) % mod * pw(j, mod - 2) % mod;
		}
	}
	g[0].pb({1, 1});
	for(int i = 1; i <= n; i++){
		ll x = 0;
		for(int j = 0; j < Sz(vec) - 1; j++){
			if(vec[j] < a[i] || b[i] <= vec[j]){
				x = (x + g[j].back().S) % mod;
				continue;
			}
			ll y = x * pre[j][1] % mod;
			for(int k = 0; k < Sz(g[j]); k++){
				y = (y + g[j][Sz(g[j]) - 1 - k].F * pre[j][k + 2]) % mod;
			}
			ll x2 = (x + g[j].back().S) % mod;
			g[j].pb(Mp(x, y));
			x = x2;
		}
	}
	int ans = 0;
	for(int i = 0; i < Sz(vec) - 1; i++){
		ans += g[i].back().S;
		if(ans >= mod) ans -= mod;
	}
	cout << (ans - 1 + mod) % mod << "\n";

	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 8364 KB Output is correct
2 Correct 149 ms 8424 KB Output is correct
3 Correct 141 ms 8336 KB Output is correct
4 Correct 145 ms 8392 KB Output is correct
5 Correct 143 ms 8304 KB Output is correct
6 Correct 147 ms 8596 KB Output is correct
7 Correct 143 ms 8400 KB Output is correct
8 Correct 150 ms 8316 KB Output is correct
9 Correct 142 ms 8356 KB Output is correct
10 Correct 152 ms 8488 KB Output is correct
11 Correct 143 ms 8396 KB Output is correct
12 Correct 146 ms 8304 KB Output is correct
13 Correct 146 ms 8408 KB Output is correct
14 Correct 146 ms 8368 KB Output is correct
15 Correct 145 ms 8384 KB Output is correct
16 Correct 26 ms 1700 KB Output is correct
17 Correct 27 ms 1840 KB Output is correct
18 Correct 27 ms 1804 KB Output is correct
19 Correct 27 ms 1876 KB Output is correct
20 Correct 27 ms 1748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 8364 KB Output is correct
2 Correct 149 ms 8424 KB Output is correct
3 Correct 141 ms 8336 KB Output is correct
4 Correct 145 ms 8392 KB Output is correct
5 Correct 143 ms 8304 KB Output is correct
6 Correct 147 ms 8596 KB Output is correct
7 Correct 143 ms 8400 KB Output is correct
8 Correct 150 ms 8316 KB Output is correct
9 Correct 142 ms 8356 KB Output is correct
10 Correct 152 ms 8488 KB Output is correct
11 Correct 143 ms 8396 KB Output is correct
12 Correct 146 ms 8304 KB Output is correct
13 Correct 146 ms 8408 KB Output is correct
14 Correct 146 ms 8368 KB Output is correct
15 Correct 145 ms 8384 KB Output is correct
16 Correct 26 ms 1700 KB Output is correct
17 Correct 27 ms 1840 KB Output is correct
18 Correct 27 ms 1804 KB Output is correct
19 Correct 27 ms 1876 KB Output is correct
20 Correct 27 ms 1748 KB Output is correct
21 Correct 201 ms 11220 KB Output is correct
22 Correct 199 ms 11340 KB Output is correct
23 Correct 190 ms 10724 KB Output is correct
24 Correct 199 ms 11060 KB Output is correct
25 Correct 198 ms 10916 KB Output is correct
26 Correct 281 ms 12060 KB Output is correct
27 Correct 284 ms 12236 KB Output is correct
28 Correct 272 ms 11980 KB Output is correct
29 Correct 275 ms 11976 KB Output is correct
30 Correct 140 ms 8412 KB Output is correct
31 Correct 141 ms 8316 KB Output is correct
32 Correct 143 ms 8316 KB Output is correct
33 Correct 150 ms 8552 KB Output is correct
34 Correct 142 ms 8396 KB Output is correct
35 Correct 142 ms 8348 KB Output is correct
36 Correct 145 ms 8396 KB Output is correct
37 Correct 150 ms 8336 KB Output is correct
38 Correct 142 ms 8396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2040 KB Output is correct
2 Correct 28 ms 1996 KB Output is correct
3 Correct 30 ms 2108 KB Output is correct
4 Correct 28 ms 2132 KB Output is correct
5 Correct 29 ms 2128 KB Output is correct
6 Correct 32 ms 2160 KB Output is correct
7 Correct 31 ms 2152 KB Output is correct
8 Correct 33 ms 2260 KB Output is correct
9 Correct 30 ms 2180 KB Output is correct
10 Correct 30 ms 2168 KB Output is correct
11 Correct 30 ms 2032 KB Output is correct
12 Correct 30 ms 2052 KB Output is correct
13 Correct 30 ms 2116 KB Output is correct
14 Correct 29 ms 2132 KB Output is correct
15 Correct 29 ms 1996 KB Output is correct
16 Correct 18 ms 1364 KB Output is correct
17 Correct 18 ms 1384 KB Output is correct
18 Correct 17 ms 1300 KB Output is correct
19 Correct 17 ms 1376 KB Output is correct
20 Correct 16 ms 1360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 8364 KB Output is correct
2 Correct 149 ms 8424 KB Output is correct
3 Correct 141 ms 8336 KB Output is correct
4 Correct 145 ms 8392 KB Output is correct
5 Correct 143 ms 8304 KB Output is correct
6 Correct 147 ms 8596 KB Output is correct
7 Correct 143 ms 8400 KB Output is correct
8 Correct 150 ms 8316 KB Output is correct
9 Correct 142 ms 8356 KB Output is correct
10 Correct 152 ms 8488 KB Output is correct
11 Correct 143 ms 8396 KB Output is correct
12 Correct 146 ms 8304 KB Output is correct
13 Correct 146 ms 8408 KB Output is correct
14 Correct 146 ms 8368 KB Output is correct
15 Correct 145 ms 8384 KB Output is correct
16 Correct 26 ms 1700 KB Output is correct
17 Correct 27 ms 1840 KB Output is correct
18 Correct 27 ms 1804 KB Output is correct
19 Correct 27 ms 1876 KB Output is correct
20 Correct 27 ms 1748 KB Output is correct
21 Correct 201 ms 11220 KB Output is correct
22 Correct 199 ms 11340 KB Output is correct
23 Correct 190 ms 10724 KB Output is correct
24 Correct 199 ms 11060 KB Output is correct
25 Correct 198 ms 10916 KB Output is correct
26 Correct 281 ms 12060 KB Output is correct
27 Correct 284 ms 12236 KB Output is correct
28 Correct 272 ms 11980 KB Output is correct
29 Correct 275 ms 11976 KB Output is correct
30 Correct 140 ms 8412 KB Output is correct
31 Correct 141 ms 8316 KB Output is correct
32 Correct 143 ms 8316 KB Output is correct
33 Correct 150 ms 8552 KB Output is correct
34 Correct 142 ms 8396 KB Output is correct
35 Correct 142 ms 8348 KB Output is correct
36 Correct 145 ms 8396 KB Output is correct
37 Correct 150 ms 8336 KB Output is correct
38 Correct 142 ms 8396 KB Output is correct
39 Correct 32 ms 2040 KB Output is correct
40 Correct 28 ms 1996 KB Output is correct
41 Correct 30 ms 2108 KB Output is correct
42 Correct 28 ms 2132 KB Output is correct
43 Correct 29 ms 2128 KB Output is correct
44 Correct 32 ms 2160 KB Output is correct
45 Correct 31 ms 2152 KB Output is correct
46 Correct 33 ms 2260 KB Output is correct
47 Correct 30 ms 2180 KB Output is correct
48 Correct 30 ms 2168 KB Output is correct
49 Correct 30 ms 2032 KB Output is correct
50 Correct 30 ms 2052 KB Output is correct
51 Correct 30 ms 2116 KB Output is correct
52 Correct 29 ms 2132 KB Output is correct
53 Correct 29 ms 1996 KB Output is correct
54 Correct 18 ms 1364 KB Output is correct
55 Correct 18 ms 1384 KB Output is correct
56 Correct 17 ms 1300 KB Output is correct
57 Correct 17 ms 1376 KB Output is correct
58 Correct 16 ms 1360 KB Output is correct
59 Correct 222 ms 12184 KB Output is correct
60 Correct 212 ms 11812 KB Output is correct
61 Correct 216 ms 11788 KB Output is correct
62 Correct 222 ms 12748 KB Output is correct
63 Correct 213 ms 11852 KB Output is correct
64 Correct 326 ms 13672 KB Output is correct
65 Correct 319 ms 13608 KB Output is correct
66 Correct 327 ms 13704 KB Output is correct
67 Correct 317 ms 13644 KB Output is correct
68 Correct 324 ms 13700 KB Output is correct
69 Correct 208 ms 11736 KB Output is correct
70 Correct 210 ms 11632 KB Output is correct
71 Correct 218 ms 11720 KB Output is correct
72 Correct 213 ms 11756 KB Output is correct
73 Correct 212 ms 11644 KB Output is correct
74 Correct 42 ms 2636 KB Output is correct
75 Correct 44 ms 2556 KB Output is correct
76 Correct 42 ms 2468 KB Output is correct
77 Correct 41 ms 2576 KB Output is correct
78 Correct 42 ms 2632 KB Output is correct