답안 #667330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667330 2022-12-01T06:44:02 Z NothingXD Boat (APIO16_boat) C++17
100 / 100
1325 ms 7408 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];
		CC[i][0] = 1;
		for (int j = 1; j <= n; j++){
			CC[i][j] = 1ll * CC[i][j-1] * (tmp - j + 1) % mod * inv[j] % 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:90:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |  for (int i = 0; i + 1 < num.size(); i++){
      |                  ~~~~~~^~~~~~~~~~~~
boat.cpp:91:7: warning: unused variable 'tmp' [-Wunused-variable]
   91 |   int tmp = num[i+1] - num[i];
      |       ^~~
boat.cpp:100:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |  for (int i = 0; i + 1 < num.size(); i++) dp[0][i] = 1;
      |                  ~~~~~~^~~~~~~~~~~~
boat.cpp:102:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |   for (int j = 1; j + 1 < num.size(); j++){
      |                   ~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 580 ms 7400 KB Output is correct
2 Correct 599 ms 7376 KB Output is correct
3 Correct 608 ms 7368 KB Output is correct
4 Correct 587 ms 7320 KB Output is correct
5 Correct 602 ms 7324 KB Output is correct
6 Correct 569 ms 7332 KB Output is correct
7 Correct 577 ms 7380 KB Output is correct
8 Correct 580 ms 7264 KB Output is correct
9 Correct 614 ms 7320 KB Output is correct
10 Correct 574 ms 7232 KB Output is correct
11 Correct 570 ms 7224 KB Output is correct
12 Correct 570 ms 7312 KB Output is correct
13 Correct 570 ms 7264 KB Output is correct
14 Correct 572 ms 7272 KB Output is correct
15 Correct 574 ms 7388 KB Output is correct
16 Correct 104 ms 4044 KB Output is correct
17 Correct 111 ms 4096 KB Output is correct
18 Correct 107 ms 4012 KB Output is correct
19 Correct 115 ms 4044 KB Output is correct
20 Correct 107 ms 3964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 580 ms 7400 KB Output is correct
2 Correct 599 ms 7376 KB Output is correct
3 Correct 608 ms 7368 KB Output is correct
4 Correct 587 ms 7320 KB Output is correct
5 Correct 602 ms 7324 KB Output is correct
6 Correct 569 ms 7332 KB Output is correct
7 Correct 577 ms 7380 KB Output is correct
8 Correct 580 ms 7264 KB Output is correct
9 Correct 614 ms 7320 KB Output is correct
10 Correct 574 ms 7232 KB Output is correct
11 Correct 570 ms 7224 KB Output is correct
12 Correct 570 ms 7312 KB Output is correct
13 Correct 570 ms 7264 KB Output is correct
14 Correct 572 ms 7272 KB Output is correct
15 Correct 574 ms 7388 KB Output is correct
16 Correct 104 ms 4044 KB Output is correct
17 Correct 111 ms 4096 KB Output is correct
18 Correct 107 ms 4012 KB Output is correct
19 Correct 115 ms 4044 KB Output is correct
20 Correct 107 ms 3964 KB Output is correct
21 Correct 693 ms 6944 KB Output is correct
22 Correct 682 ms 6912 KB Output is correct
23 Correct 663 ms 6880 KB Output is correct
24 Correct 665 ms 6920 KB Output is correct
25 Correct 676 ms 7000 KB Output is correct
26 Correct 723 ms 6960 KB Output is correct
27 Correct 731 ms 6880 KB Output is correct
28 Correct 710 ms 6808 KB Output is correct
29 Correct 700 ms 6724 KB Output is correct
30 Correct 604 ms 7320 KB Output is correct
31 Correct 584 ms 7408 KB Output is correct
32 Correct 599 ms 7212 KB Output is correct
33 Correct 594 ms 7248 KB Output is correct
34 Correct 595 ms 7212 KB Output is correct
35 Correct 569 ms 7276 KB Output is correct
36 Correct 554 ms 7304 KB Output is correct
37 Correct 568 ms 7332 KB Output is correct
38 Correct 562 ms 7276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1748 KB Output is correct
2 Correct 11 ms 1748 KB Output is correct
3 Correct 11 ms 1664 KB Output is correct
4 Correct 11 ms 1676 KB Output is correct
5 Correct 12 ms 1732 KB Output is correct
6 Correct 12 ms 1748 KB Output is correct
7 Correct 12 ms 1636 KB Output is correct
8 Correct 13 ms 1760 KB Output is correct
9 Correct 12 ms 1748 KB Output is correct
10 Correct 12 ms 1748 KB Output is correct
11 Correct 11 ms 1732 KB Output is correct
12 Correct 10 ms 1748 KB Output is correct
13 Correct 12 ms 1688 KB Output is correct
14 Correct 11 ms 1708 KB Output is correct
15 Correct 11 ms 1668 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 6 ms 1384 KB Output is correct
18 Correct 8 ms 1316 KB Output is correct
19 Correct 6 ms 1364 KB Output is correct
20 Correct 6 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 580 ms 7400 KB Output is correct
2 Correct 599 ms 7376 KB Output is correct
3 Correct 608 ms 7368 KB Output is correct
4 Correct 587 ms 7320 KB Output is correct
5 Correct 602 ms 7324 KB Output is correct
6 Correct 569 ms 7332 KB Output is correct
7 Correct 577 ms 7380 KB Output is correct
8 Correct 580 ms 7264 KB Output is correct
9 Correct 614 ms 7320 KB Output is correct
10 Correct 574 ms 7232 KB Output is correct
11 Correct 570 ms 7224 KB Output is correct
12 Correct 570 ms 7312 KB Output is correct
13 Correct 570 ms 7264 KB Output is correct
14 Correct 572 ms 7272 KB Output is correct
15 Correct 574 ms 7388 KB Output is correct
16 Correct 104 ms 4044 KB Output is correct
17 Correct 111 ms 4096 KB Output is correct
18 Correct 107 ms 4012 KB Output is correct
19 Correct 115 ms 4044 KB Output is correct
20 Correct 107 ms 3964 KB Output is correct
21 Correct 693 ms 6944 KB Output is correct
22 Correct 682 ms 6912 KB Output is correct
23 Correct 663 ms 6880 KB Output is correct
24 Correct 665 ms 6920 KB Output is correct
25 Correct 676 ms 7000 KB Output is correct
26 Correct 723 ms 6960 KB Output is correct
27 Correct 731 ms 6880 KB Output is correct
28 Correct 710 ms 6808 KB Output is correct
29 Correct 700 ms 6724 KB Output is correct
30 Correct 604 ms 7320 KB Output is correct
31 Correct 584 ms 7408 KB Output is correct
32 Correct 599 ms 7212 KB Output is correct
33 Correct 594 ms 7248 KB Output is correct
34 Correct 595 ms 7212 KB Output is correct
35 Correct 569 ms 7276 KB Output is correct
36 Correct 554 ms 7304 KB Output is correct
37 Correct 568 ms 7332 KB Output is correct
38 Correct 562 ms 7276 KB Output is correct
39 Correct 11 ms 1748 KB Output is correct
40 Correct 11 ms 1748 KB Output is correct
41 Correct 11 ms 1664 KB Output is correct
42 Correct 11 ms 1676 KB Output is correct
43 Correct 12 ms 1732 KB Output is correct
44 Correct 12 ms 1748 KB Output is correct
45 Correct 12 ms 1636 KB Output is correct
46 Correct 13 ms 1760 KB Output is correct
47 Correct 12 ms 1748 KB Output is correct
48 Correct 12 ms 1748 KB Output is correct
49 Correct 11 ms 1732 KB Output is correct
50 Correct 10 ms 1748 KB Output is correct
51 Correct 12 ms 1688 KB Output is correct
52 Correct 11 ms 1708 KB Output is correct
53 Correct 11 ms 1668 KB Output is correct
54 Correct 6 ms 1364 KB Output is correct
55 Correct 6 ms 1384 KB Output is correct
56 Correct 8 ms 1316 KB Output is correct
57 Correct 6 ms 1364 KB Output is correct
58 Correct 6 ms 1364 KB Output is correct
59 Correct 1265 ms 7332 KB Output is correct
60 Correct 1213 ms 7336 KB Output is correct
61 Correct 1201 ms 7340 KB Output is correct
62 Correct 1263 ms 7280 KB Output is correct
63 Correct 1221 ms 7396 KB Output is correct
64 Correct 1318 ms 7244 KB Output is correct
65 Correct 1325 ms 7296 KB Output is correct
66 Correct 1285 ms 7400 KB Output is correct
67 Correct 1275 ms 7272 KB Output is correct
68 Correct 1278 ms 7344 KB Output is correct
69 Correct 1151 ms 7392 KB Output is correct
70 Correct 1145 ms 7232 KB Output is correct
71 Correct 1154 ms 7392 KB Output is correct
72 Correct 1175 ms 7392 KB Output is correct
73 Correct 1170 ms 7368 KB Output is correct
74 Correct 197 ms 4064 KB Output is correct
75 Correct 190 ms 3984 KB Output is correct
76 Correct 195 ms 4092 KB Output is correct
77 Correct 195 ms 3996 KB Output is correct
78 Correct 194 ms 3964 KB Output is correct