Submission #667324

# Submission time Handle Problem Language Result Execution time Memory
667324 2022-12-01T06:36:33 Z NothingXD Boat (APIO16_boat) C++17
58 / 100
2000 ms 7460 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
/*typedef __uint128_t L;
struct FastMod {
  ull b, m;
  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
  ull reduce(ull a) {
    ull q = (ull)((L(m) * a) >> 64);
    ull r = a - q * b; // can be proven that 0 <= r < 2*b
    return r >= b ? r - b : r;
  }
};
FastMod FM(2);*/
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 500 + 10;
const int mod = 1e9 + 7;
int n, dp[maxn][maxn << 1], C[maxn][maxn], CC[maxn << 1][maxn], f[maxn << 1][maxn], inv[maxn], a[maxn], b[maxn];
vector<int> num;

int add(int x, int y){
	int res = x + y;
	if (res >= mod) return res - mod;
	if (res < 0) return res + mod;
	return res;
}

int pwr(int a, int b){
	int res = 1;
	for (; b; b>>=1, a = 1ll * a * a % mod) if (b & 1) res = 1ll * res * a % mod;
	return res;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		num.push_back(a[i]);
		num.push_back(b[i]+1);
	}

	num.push_back(0);

	sort(all(num));
	num.resize(distance(num.begin(), unique(all(num))));

	for (int i = 1; i <= n; i++){
		inv[i] = pwr(i, mod-2);
	}

	for (int i = 0; i <= n; i++) C[i][0] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			C[i][j] = add(C[i-1][j-1], C[i-1][j]);
		}
	}


	for (int i = 0; i + 1 < num.size(); i++){
		int tmp = num[i+1] - num[i];
		for (int j = 1; j <= n; j++){
			if (j > tmp) continue;
			CC[i][j] = 1;
			for (int k = 1; k <= j; k++){
				CC[i][j] = 1ll * CC[i][j] * (tmp - k + 1) % mod * inv[k] % mod;
			}
		}
	}
	for (int i = 0; i + 1 < num.size(); i++){
		int tmp = num[i+1] - num[i];
		for (int j = 1; j <= n; j++){
			for (int k = 1; k <= j; k++){
				f[i][j] = add(f[i][j], 1ll * CC[i][k] * C[j-1][k-1] % mod);
			}
		}
	}


	for (int i = 0; i + 1 < num.size(); i++) dp[0][i] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j + 1 < num.size(); j++){
			dp[i][j] = dp[i][j-1];
			if (a[i] > num[j] || b[i] < num[j]) continue;
			int cnt = 1;
			for (int k = i-1; ~k; k--){
				dp[i][j] = add(dp[i][j], 1ll * dp[k][j-1] * f[j][cnt] % mod);
				if (a[k] <= num[j] && num[j] <= b[k]) cnt++;
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++){
		ans = add(ans, dp[i][num.size()-2]);
	}
	cout << ans << '\n';
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:83:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  for (int i = 0; i + 1 < num.size(); i++){
      |                  ~~~~~~^~~~~~~~~~~~
boat.cpp:93:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |  for (int i = 0; i + 1 < num.size(); i++){
      |                  ~~~~~~^~~~~~~~~~~~
boat.cpp:94:7: warning: unused variable 'tmp' [-Wunused-variable]
   94 |   int tmp = num[i+1] - num[i];
      |       ^~~
boat.cpp:103:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |  for (int i = 0; i + 1 < num.size(); i++) dp[0][i] = 1;
      |                  ~~~~~~^~~~~~~~~~~~
boat.cpp:105:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |   for (int j = 1; j + 1 < num.size(); j++){
      |                   ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1157 ms 7244 KB Output is correct
2 Correct 1162 ms 7300 KB Output is correct
3 Correct 1144 ms 7380 KB Output is correct
4 Correct 1158 ms 7324 KB Output is correct
5 Correct 1150 ms 7312 KB Output is correct
6 Correct 1144 ms 7352 KB Output is correct
7 Correct 1145 ms 7336 KB Output is correct
8 Correct 1145 ms 7280 KB Output is correct
9 Correct 1140 ms 7348 KB Output is correct
10 Correct 1142 ms 7348 KB Output is correct
11 Correct 1151 ms 7412 KB Output is correct
12 Correct 1150 ms 7320 KB Output is correct
13 Correct 1150 ms 7236 KB Output is correct
14 Correct 1145 ms 7336 KB Output is correct
15 Correct 1149 ms 7460 KB Output is correct
16 Correct 206 ms 3968 KB Output is correct
17 Correct 225 ms 4048 KB Output is correct
18 Correct 219 ms 3988 KB Output is correct
19 Correct 221 ms 4056 KB Output is correct
20 Correct 218 ms 4032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1157 ms 7244 KB Output is correct
2 Correct 1162 ms 7300 KB Output is correct
3 Correct 1144 ms 7380 KB Output is correct
4 Correct 1158 ms 7324 KB Output is correct
5 Correct 1150 ms 7312 KB Output is correct
6 Correct 1144 ms 7352 KB Output is correct
7 Correct 1145 ms 7336 KB Output is correct
8 Correct 1145 ms 7280 KB Output is correct
9 Correct 1140 ms 7348 KB Output is correct
10 Correct 1142 ms 7348 KB Output is correct
11 Correct 1151 ms 7412 KB Output is correct
12 Correct 1150 ms 7320 KB Output is correct
13 Correct 1150 ms 7236 KB Output is correct
14 Correct 1145 ms 7336 KB Output is correct
15 Correct 1149 ms 7460 KB Output is correct
16 Correct 206 ms 3968 KB Output is correct
17 Correct 225 ms 4048 KB Output is correct
18 Correct 219 ms 3988 KB Output is correct
19 Correct 221 ms 4056 KB Output is correct
20 Correct 218 ms 4032 KB Output is correct
21 Correct 700 ms 7072 KB Output is correct
22 Correct 676 ms 6960 KB Output is correct
23 Correct 664 ms 6964 KB Output is correct
24 Correct 683 ms 7108 KB Output is correct
25 Correct 740 ms 6944 KB Output is correct
26 Correct 733 ms 6800 KB Output is correct
27 Correct 783 ms 6820 KB Output is correct
28 Correct 742 ms 6804 KB Output is correct
29 Correct 762 ms 6724 KB Output is correct
30 Correct 1103 ms 7324 KB Output is correct
31 Correct 1086 ms 7256 KB Output is correct
32 Correct 1118 ms 7224 KB Output is correct
33 Correct 1110 ms 7248 KB Output is correct
34 Correct 1094 ms 7264 KB Output is correct
35 Correct 1094 ms 7332 KB Output is correct
36 Correct 1100 ms 7268 KB Output is correct
37 Correct 1164 ms 7272 KB Output is correct
38 Correct 1091 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1748 KB Output is correct
2 Correct 20 ms 1676 KB Output is correct
3 Correct 20 ms 1732 KB Output is correct
4 Correct 23 ms 1748 KB Output is correct
5 Correct 21 ms 1740 KB Output is correct
6 Correct 22 ms 1672 KB Output is correct
7 Correct 22 ms 1740 KB Output is correct
8 Correct 21 ms 1748 KB Output is correct
9 Correct 21 ms 1652 KB Output is correct
10 Correct 22 ms 1740 KB Output is correct
11 Correct 21 ms 1660 KB Output is correct
12 Correct 19 ms 1736 KB Output is correct
13 Correct 21 ms 1740 KB Output is correct
14 Correct 23 ms 1700 KB Output is correct
15 Correct 22 ms 1748 KB Output is correct
16 Correct 10 ms 1364 KB Output is correct
17 Correct 10 ms 1364 KB Output is correct
18 Correct 11 ms 1364 KB Output is correct
19 Correct 10 ms 1360 KB Output is correct
20 Correct 11 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1157 ms 7244 KB Output is correct
2 Correct 1162 ms 7300 KB Output is correct
3 Correct 1144 ms 7380 KB Output is correct
4 Correct 1158 ms 7324 KB Output is correct
5 Correct 1150 ms 7312 KB Output is correct
6 Correct 1144 ms 7352 KB Output is correct
7 Correct 1145 ms 7336 KB Output is correct
8 Correct 1145 ms 7280 KB Output is correct
9 Correct 1140 ms 7348 KB Output is correct
10 Correct 1142 ms 7348 KB Output is correct
11 Correct 1151 ms 7412 KB Output is correct
12 Correct 1150 ms 7320 KB Output is correct
13 Correct 1150 ms 7236 KB Output is correct
14 Correct 1145 ms 7336 KB Output is correct
15 Correct 1149 ms 7460 KB Output is correct
16 Correct 206 ms 3968 KB Output is correct
17 Correct 225 ms 4048 KB Output is correct
18 Correct 219 ms 3988 KB Output is correct
19 Correct 221 ms 4056 KB Output is correct
20 Correct 218 ms 4032 KB Output is correct
21 Correct 700 ms 7072 KB Output is correct
22 Correct 676 ms 6960 KB Output is correct
23 Correct 664 ms 6964 KB Output is correct
24 Correct 683 ms 7108 KB Output is correct
25 Correct 740 ms 6944 KB Output is correct
26 Correct 733 ms 6800 KB Output is correct
27 Correct 783 ms 6820 KB Output is correct
28 Correct 742 ms 6804 KB Output is correct
29 Correct 762 ms 6724 KB Output is correct
30 Correct 1103 ms 7324 KB Output is correct
31 Correct 1086 ms 7256 KB Output is correct
32 Correct 1118 ms 7224 KB Output is correct
33 Correct 1110 ms 7248 KB Output is correct
34 Correct 1094 ms 7264 KB Output is correct
35 Correct 1094 ms 7332 KB Output is correct
36 Correct 1100 ms 7268 KB Output is correct
37 Correct 1164 ms 7272 KB Output is correct
38 Correct 1091 ms 7372 KB Output is correct
39 Correct 20 ms 1748 KB Output is correct
40 Correct 20 ms 1676 KB Output is correct
41 Correct 20 ms 1732 KB Output is correct
42 Correct 23 ms 1748 KB Output is correct
43 Correct 21 ms 1740 KB Output is correct
44 Correct 22 ms 1672 KB Output is correct
45 Correct 22 ms 1740 KB Output is correct
46 Correct 21 ms 1748 KB Output is correct
47 Correct 21 ms 1652 KB Output is correct
48 Correct 22 ms 1740 KB Output is correct
49 Correct 21 ms 1660 KB Output is correct
50 Correct 19 ms 1736 KB Output is correct
51 Correct 21 ms 1740 KB Output is correct
52 Correct 23 ms 1700 KB Output is correct
53 Correct 22 ms 1748 KB Output is correct
54 Correct 10 ms 1364 KB Output is correct
55 Correct 10 ms 1364 KB Output is correct
56 Correct 11 ms 1364 KB Output is correct
57 Correct 10 ms 1360 KB Output is correct
58 Correct 11 ms 1364 KB Output is correct
59 Execution timed out 2068 ms 6312 KB Time limit exceeded
60 Halted 0 ms 0 KB -