Submission #1020837

# Submission time Handle Problem Language Result Execution time Memory
1020837 2024-07-12T10:22:26 Z flappybird Boat (APIO16_boat) C++17
100 / 100
1533 ms 8532 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 510
#define MAXQ 101010
#define INF 1000000100
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
int A[MAX];
int B[MAX];
int sz[MAX * 2];
ll C[MAX * 2][MAX];
ll dp[MAX][MAX * 2];
ll mpow(ll x, ll y = MOD - 2) {
	if (!y) return 1;
	ll res = mpow(x, y >> 1);
	res *= res;
	res %= MOD;
	if (y & 1) res = (res * x) % MOD;
	return res;
}
ll rev[MAX * 2];
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	int i, j, k;
	vector<int> v;
	for (i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		B[i]++;
		v.push_back(A[i]);
		v.push_back(B[i]);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	for (i = 1; i <= N; i++) {
		A[i] = lower_bound(v.begin(), v.end(), A[i]) - v.begin();
		B[i] = lower_bound(v.begin(), v.end(), B[i]) - v.begin();
	}
	for (i = 1; i <= N * 2; i++) rev[i] = mpow(i);
	int X = v.size() - 1;
	for (i = 0; i < X; i++) {
		sz[i] = v[i + 1] - v[i];
		for (j = 1; j <= N; j++) {
			ll c1, c2;
			c1 = 1;
			c2 = sz[i];
			C[i][j] += c1 * c2;
			C[i][j] %= MOD;
			for (k = 0; k < j - 1; k++) {
				c1 *= j - 1 - k;
				c1 %= MOD;
				c1 *= rev[k + 1];
				c1 %= MOD;
				c2 *= sz[i] - (k + 1);
				c2 %= MOD;
				c2 *= rev[k + 2];
				c2 %= MOD;
				C[i][j] += c1 * c2;
				C[i][j] %= MOD;
			}
		}
	}
	for (i = 1; i <= N; i++) {
		int cnt = 1;
		if (A[i] == 0) {
			for (j = 1; j < i; j++) if (A[j] == 0) cnt++;
			dp[i][0] += C[0][cnt];
			dp[i][0] %= MOD;
		}
		for (j = 1; j < X; j++) {
			dp[i][j] = dp[i][j - 1];
			if (B[i] <= j) continue;
			if (j < A[i]) continue;
			cnt = 1;
			for (k = i - 1; k >= 1; k--) {
				dp[i][j] += C[j][cnt] * dp[k][j - 1];
				dp[i][j] %= MOD;
				if (A[k] <= j && j < B[k]) cnt++;
			}
			dp[i][j] += C[j][cnt];
			dp[i][j] %= MOD;
		}
	}
	ll ans = 0;
	for (i = 1; i <= N; i++) ans = (ans + dp[i][X - 1]) % MOD;
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1281 ms 8464 KB Output is correct
2 Correct 1284 ms 8300 KB Output is correct
3 Correct 1289 ms 8276 KB Output is correct
4 Correct 1283 ms 8432 KB Output is correct
5 Correct 1292 ms 8360 KB Output is correct
6 Correct 1291 ms 8452 KB Output is correct
7 Correct 1285 ms 8276 KB Output is correct
8 Correct 1283 ms 8344 KB Output is correct
9 Correct 1290 ms 8260 KB Output is correct
10 Correct 1275 ms 8360 KB Output is correct
11 Correct 1272 ms 8264 KB Output is correct
12 Correct 1281 ms 8380 KB Output is correct
13 Correct 1281 ms 8228 KB Output is correct
14 Correct 1272 ms 8280 KB Output is correct
15 Correct 1288 ms 8408 KB Output is correct
16 Correct 226 ms 3832 KB Output is correct
17 Correct 242 ms 3844 KB Output is correct
18 Correct 231 ms 3852 KB Output is correct
19 Correct 242 ms 3860 KB Output is correct
20 Correct 236 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1281 ms 8464 KB Output is correct
2 Correct 1284 ms 8300 KB Output is correct
3 Correct 1289 ms 8276 KB Output is correct
4 Correct 1283 ms 8432 KB Output is correct
5 Correct 1292 ms 8360 KB Output is correct
6 Correct 1291 ms 8452 KB Output is correct
7 Correct 1285 ms 8276 KB Output is correct
8 Correct 1283 ms 8344 KB Output is correct
9 Correct 1290 ms 8260 KB Output is correct
10 Correct 1275 ms 8360 KB Output is correct
11 Correct 1272 ms 8264 KB Output is correct
12 Correct 1281 ms 8380 KB Output is correct
13 Correct 1281 ms 8228 KB Output is correct
14 Correct 1272 ms 8280 KB Output is correct
15 Correct 1288 ms 8408 KB Output is correct
16 Correct 226 ms 3832 KB Output is correct
17 Correct 242 ms 3844 KB Output is correct
18 Correct 231 ms 3852 KB Output is correct
19 Correct 242 ms 3860 KB Output is correct
20 Correct 236 ms 3924 KB Output is correct
21 Correct 1323 ms 8048 KB Output is correct
22 Correct 1330 ms 7904 KB Output is correct
23 Correct 1301 ms 7940 KB Output is correct
24 Correct 1304 ms 8052 KB Output is correct
25 Correct 1299 ms 7932 KB Output is correct
26 Correct 1346 ms 7764 KB Output is correct
27 Correct 1353 ms 8036 KB Output is correct
28 Correct 1339 ms 8052 KB Output is correct
29 Correct 1309 ms 7756 KB Output is correct
30 Correct 1273 ms 8292 KB Output is correct
31 Correct 1265 ms 8440 KB Output is correct
32 Correct 1227 ms 8276 KB Output is correct
33 Correct 1262 ms 8388 KB Output is correct
34 Correct 1272 ms 8288 KB Output is correct
35 Correct 1268 ms 8404 KB Output is correct
36 Correct 1267 ms 8208 KB Output is correct
37 Correct 1266 ms 8276 KB Output is correct
38 Correct 1266 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1624 KB Output is correct
2 Correct 12 ms 1848 KB Output is correct
3 Correct 13 ms 1760 KB Output is correct
4 Correct 13 ms 1628 KB Output is correct
5 Correct 13 ms 1772 KB Output is correct
6 Correct 14 ms 1624 KB Output is correct
7 Correct 15 ms 1628 KB Output is correct
8 Correct 15 ms 1876 KB Output is correct
9 Correct 14 ms 1628 KB Output is correct
10 Correct 13 ms 1628 KB Output is correct
11 Correct 12 ms 1776 KB Output is correct
12 Correct 12 ms 1628 KB Output is correct
13 Correct 12 ms 1728 KB Output is correct
14 Correct 13 ms 1628 KB Output is correct
15 Correct 13 ms 1628 KB Output is correct
16 Correct 8 ms 1372 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 7 ms 1372 KB Output is correct
19 Correct 7 ms 1288 KB Output is correct
20 Correct 7 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1281 ms 8464 KB Output is correct
2 Correct 1284 ms 8300 KB Output is correct
3 Correct 1289 ms 8276 KB Output is correct
4 Correct 1283 ms 8432 KB Output is correct
5 Correct 1292 ms 8360 KB Output is correct
6 Correct 1291 ms 8452 KB Output is correct
7 Correct 1285 ms 8276 KB Output is correct
8 Correct 1283 ms 8344 KB Output is correct
9 Correct 1290 ms 8260 KB Output is correct
10 Correct 1275 ms 8360 KB Output is correct
11 Correct 1272 ms 8264 KB Output is correct
12 Correct 1281 ms 8380 KB Output is correct
13 Correct 1281 ms 8228 KB Output is correct
14 Correct 1272 ms 8280 KB Output is correct
15 Correct 1288 ms 8408 KB Output is correct
16 Correct 226 ms 3832 KB Output is correct
17 Correct 242 ms 3844 KB Output is correct
18 Correct 231 ms 3852 KB Output is correct
19 Correct 242 ms 3860 KB Output is correct
20 Correct 236 ms 3924 KB Output is correct
21 Correct 1323 ms 8048 KB Output is correct
22 Correct 1330 ms 7904 KB Output is correct
23 Correct 1301 ms 7940 KB Output is correct
24 Correct 1304 ms 8052 KB Output is correct
25 Correct 1299 ms 7932 KB Output is correct
26 Correct 1346 ms 7764 KB Output is correct
27 Correct 1353 ms 8036 KB Output is correct
28 Correct 1339 ms 8052 KB Output is correct
29 Correct 1309 ms 7756 KB Output is correct
30 Correct 1273 ms 8292 KB Output is correct
31 Correct 1265 ms 8440 KB Output is correct
32 Correct 1227 ms 8276 KB Output is correct
33 Correct 1262 ms 8388 KB Output is correct
34 Correct 1272 ms 8288 KB Output is correct
35 Correct 1268 ms 8404 KB Output is correct
36 Correct 1267 ms 8208 KB Output is correct
37 Correct 1266 ms 8276 KB Output is correct
38 Correct 1266 ms 8272 KB Output is correct
39 Correct 14 ms 1624 KB Output is correct
40 Correct 12 ms 1848 KB Output is correct
41 Correct 13 ms 1760 KB Output is correct
42 Correct 13 ms 1628 KB Output is correct
43 Correct 13 ms 1772 KB Output is correct
44 Correct 14 ms 1624 KB Output is correct
45 Correct 15 ms 1628 KB Output is correct
46 Correct 15 ms 1876 KB Output is correct
47 Correct 14 ms 1628 KB Output is correct
48 Correct 13 ms 1628 KB Output is correct
49 Correct 12 ms 1776 KB Output is correct
50 Correct 12 ms 1628 KB Output is correct
51 Correct 12 ms 1728 KB Output is correct
52 Correct 13 ms 1628 KB Output is correct
53 Correct 13 ms 1628 KB Output is correct
54 Correct 8 ms 1372 KB Output is correct
55 Correct 8 ms 1372 KB Output is correct
56 Correct 7 ms 1372 KB Output is correct
57 Correct 7 ms 1288 KB Output is correct
58 Correct 7 ms 1372 KB Output is correct
59 Correct 1452 ms 8276 KB Output is correct
60 Correct 1443 ms 8276 KB Output is correct
61 Correct 1434 ms 8432 KB Output is correct
62 Correct 1453 ms 8240 KB Output is correct
63 Correct 1448 ms 8276 KB Output is correct
64 Correct 1533 ms 8464 KB Output is correct
65 Correct 1519 ms 8276 KB Output is correct
66 Correct 1492 ms 8412 KB Output is correct
67 Correct 1480 ms 8388 KB Output is correct
68 Correct 1486 ms 8532 KB Output is correct
69 Correct 1384 ms 8272 KB Output is correct
70 Correct 1390 ms 8412 KB Output is correct
71 Correct 1400 ms 8272 KB Output is correct
72 Correct 1404 ms 8392 KB Output is correct
73 Correct 1406 ms 8412 KB Output is correct
74 Correct 262 ms 3904 KB Output is correct
75 Correct 270 ms 3964 KB Output is correct
76 Correct 267 ms 3840 KB Output is correct
77 Correct 268 ms 3908 KB Output is correct
78 Correct 264 ms 3660 KB Output is correct