Submission #261893

# Submission time Handle Problem Language Result Execution time Memory
261893 2020-08-12T07:27:24 Z Saboon Boat (APIO16_boat) C++14
9 / 100
751 ms 5624 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500 + 10;
const int mod = 1e9 + 7;

int a[maxn], b[maxn];
int dp[maxn][2*maxn], pd[2*maxn][maxn], c[maxn][maxn];
int revpw[maxn];

int power(int a, int b){
	if (b == 0)
		return 1;
	int ret = power(a,b/2);
	ret = 1LL*ret*ret%mod;
	if (b & 1)
		ret = 1LL*ret*a%mod;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> cmp;
	for (int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		b[i] ++;
		cmp.push_back(a[i]);
		cmp.push_back(b[i]);
	}
	sort(cmp.begin(), cmp.end());
	cmp.resize(unique(cmp.begin(),cmp.end())-cmp.begin());
	for (int i = 1; i <= n; i++){
		a[i] = lower_bound(cmp.begin(),cmp.end(),a[i]) - cmp.begin() + 1;
		b[i] = lower_bound(cmp.begin(),cmp.end(),b[i]) - cmp.begin() + 1;
	}
	c[0][0] = 1;
	for (int N = 1; N <= n; N++){
		c[N][0] = 1;
		for (int R = 1; R <= N; R++)
			c[N][R] = (c[N][R-1]+c[N-1][R-1]) % mod;
	}
	for (int i = 1; i <= 500; i++)
		revpw[i] = power(i, mod-2);

	for (int i = 1; i < cmp.size(); i++){
		int m = cmp[i]-cmp[i-1];
		pd[i][1] = m;
		int Cmk = m;
		for (int j = 2; j <= min(n,m); j++){
			for (int k = 2; k <= j; k++){
				Cmk = 1LL*Cmk*revpw[k]%mod*(m-k+1)%mod;
				pd[i][j] = (pd[i][j] + 1LL*c[j-2][k-2]*Cmk) % mod;
			}
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i < cmp.size(); i++)
		dp[0][i] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = a[i]; j < b[i]; j++){
			int cnt = cmp[j]-cmp[j-1];
			for (int k = i-1; k >= 0; k--){
				dp[i][j] = (dp[i][j] + 1LL*pd[j][i-k]*dp[k][j-1]) % mod;
				if (a[k] > j or b[k] <= j)
					break;
			}
		}
		for (int j = a[i]; j < cmp.size(); j++)
			dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
		for (int j = 0; j < cmp.size(); j++)
			dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
	}
	cout << (dp[n][cmp.size()-1]+mod-1) % mod << endl;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < cmp.size(); i++){
                  ~~^~~~~~~~~~~~
boat.cpp:59:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < cmp.size(); i++)
                  ~~^~~~~~~~~~~~
boat.cpp:63:8: warning: unused variable 'cnt' [-Wunused-variable]
    int cnt = cmp[j]-cmp[j-1];
        ^~~
boat.cpp:70:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = a[i]; j < cmp.size(); j++)
                      ~~^~~~~~~~~~~~
boat.cpp:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < cmp.size(); j++)
                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 736 ms 5368 KB Output is correct
2 Correct 739 ms 5456 KB Output is correct
3 Correct 735 ms 5368 KB Output is correct
4 Correct 731 ms 5356 KB Output is correct
5 Correct 734 ms 5368 KB Output is correct
6 Correct 735 ms 5496 KB Output is correct
7 Correct 735 ms 5496 KB Output is correct
8 Correct 734 ms 5352 KB Output is correct
9 Correct 737 ms 5476 KB Output is correct
10 Correct 742 ms 5456 KB Output is correct
11 Correct 751 ms 5624 KB Output is correct
12 Correct 731 ms 5496 KB Output is correct
13 Correct 733 ms 5368 KB Output is correct
14 Correct 730 ms 5368 KB Output is correct
15 Correct 733 ms 5368 KB Output is correct
16 Correct 133 ms 3704 KB Output is correct
17 Correct 142 ms 3704 KB Output is correct
18 Correct 136 ms 3704 KB Output is correct
19 Correct 145 ms 3704 KB Output is correct
20 Correct 139 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 736 ms 5368 KB Output is correct
2 Correct 739 ms 5456 KB Output is correct
3 Correct 735 ms 5368 KB Output is correct
4 Correct 731 ms 5356 KB Output is correct
5 Correct 734 ms 5368 KB Output is correct
6 Correct 735 ms 5496 KB Output is correct
7 Correct 735 ms 5496 KB Output is correct
8 Correct 734 ms 5352 KB Output is correct
9 Correct 737 ms 5476 KB Output is correct
10 Correct 742 ms 5456 KB Output is correct
11 Correct 751 ms 5624 KB Output is correct
12 Correct 731 ms 5496 KB Output is correct
13 Correct 733 ms 5368 KB Output is correct
14 Correct 730 ms 5368 KB Output is correct
15 Correct 733 ms 5368 KB Output is correct
16 Correct 133 ms 3704 KB Output is correct
17 Correct 142 ms 3704 KB Output is correct
18 Correct 136 ms 3704 KB Output is correct
19 Correct 145 ms 3704 KB Output is correct
20 Correct 139 ms 3832 KB Output is correct
21 Incorrect 11 ms 5120 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 736 ms 5368 KB Output is correct
2 Correct 739 ms 5456 KB Output is correct
3 Correct 735 ms 5368 KB Output is correct
4 Correct 731 ms 5356 KB Output is correct
5 Correct 734 ms 5368 KB Output is correct
6 Correct 735 ms 5496 KB Output is correct
7 Correct 735 ms 5496 KB Output is correct
8 Correct 734 ms 5352 KB Output is correct
9 Correct 737 ms 5476 KB Output is correct
10 Correct 742 ms 5456 KB Output is correct
11 Correct 751 ms 5624 KB Output is correct
12 Correct 731 ms 5496 KB Output is correct
13 Correct 733 ms 5368 KB Output is correct
14 Correct 730 ms 5368 KB Output is correct
15 Correct 733 ms 5368 KB Output is correct
16 Correct 133 ms 3704 KB Output is correct
17 Correct 142 ms 3704 KB Output is correct
18 Correct 136 ms 3704 KB Output is correct
19 Correct 145 ms 3704 KB Output is correct
20 Correct 139 ms 3832 KB Output is correct
21 Incorrect 11 ms 5120 KB Output isn't correct
22 Halted 0 ms 0 KB -