Submission #551893

# Submission time Handle Problem Language Result Execution time Memory
551893 2022-04-21T20:36:09 Z nafis_shifat Boat (APIO16_boat) C++17
9 / 100
318 ms 20916 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1500+5;
const int inf=1e9;
const ll mod = 1e9 + 7;
ll bigmod(ll a, ll b) {
	if(b == 0) return 1;
	int mid = b / 2;

	ll res = bigmod(a, mid);
	res = res * res % mod;
	if(b % 2 == 1) return a * res % mod;
	return res;
}

ll last[mxn][mxn] = {};
ll dp[mxn][mxn] = {};
ll sum[mxn][mxn] = {};

ll fact[mxn], inv[mxn];
int main() {
	fact[0] = 1;
	inv[0] = 1;

	for(int i = 1; i < mxn; i++) {
		fact[i] = fact[i - 1] * i % mod;
		inv[i] = bigmod(fact[i], mod - 2) % mod;
	}
	int n;
	cin >> n;
	int a[n + 1], b[n + 1];
	int l[n + 1], r[n + 1];
	vector<int> v;
	v.push_back(0);
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		v.push_back(a[i]);
		v.push_back(a[i] - 1);
		v.push_back(b[i]);

	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());

	int len[v.size() + 2];
	for(int i = 1; i < v.size(); i++) len[i] = v[i] - v[i - 1];


	for(int i = 1; i <= n; i++) {
		l[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
		r[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
	}

	dp[0][0] = 1;
	for(int i = 0; i < v.size(); i++) sum[i][0] = 1;

	ll ans = 0;

    for(int p = 1; p <= n; p++) {
    	for(int i = l[p]; i <= r[p]; i++) {
    		ll tot = len[i];
    		ll found = 1;

    		for(int j = p - 1; j >= 0; j--) {
    			dp[i][j] = sum[i - 1][j] * tot % mod;
    			sum[i][p] = (sum[i][p] + dp[i][j]) % mod;

    			if(l[j] >= i && r[j] <= i) {
    				found++;
    				if(found >= len[i]) continue;
    				tot += (len[i] - found + 1) * inv[found] % mod;
    				tot %= mod;
    			}

    		}
    	}

    	for(int i = l[p]; i < v.size(); i++) sum[i][p] = (sum[i][p] + sum[i - 1][p]) % mod;

    	ans += sum[v.size() - 1][p];

    }

    cout<<ans % mod<<endl;


	
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 1; i < v.size(); i++) len[i] = v[i] - v[i - 1];
      |                 ~~^~~~~~~~~~
boat.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i = 0; i < v.size(); i++) sum[i][0] = 1;
      |                 ~~^~~~~~~~~~
boat.cpp:80:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |      for(int i = l[p]; i < v.size(); i++) sum[i][p] = (sum[i][p] + sum[i - 1][p]) % mod;
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11220 KB Output is correct
2 Correct 9 ms 11220 KB Output is correct
3 Correct 10 ms 11220 KB Output is correct
4 Correct 9 ms 11216 KB Output is correct
5 Correct 9 ms 11220 KB Output is correct
6 Correct 7 ms 10068 KB Output is correct
7 Correct 8 ms 9936 KB Output is correct
8 Correct 9 ms 10580 KB Output is correct
9 Correct 10 ms 10436 KB Output is correct
10 Correct 8 ms 10580 KB Output is correct
11 Correct 8 ms 10364 KB Output is correct
12 Correct 9 ms 11092 KB Output is correct
13 Correct 8 ms 10580 KB Output is correct
14 Correct 8 ms 10068 KB Output is correct
15 Correct 9 ms 10712 KB Output is correct
16 Correct 3 ms 2264 KB Output is correct
17 Correct 3 ms 2516 KB Output is correct
18 Correct 4 ms 2388 KB Output is correct
19 Correct 3 ms 2388 KB Output is correct
20 Correct 3 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11220 KB Output is correct
2 Correct 9 ms 11220 KB Output is correct
3 Correct 10 ms 11220 KB Output is correct
4 Correct 9 ms 11216 KB Output is correct
5 Correct 9 ms 11220 KB Output is correct
6 Correct 7 ms 10068 KB Output is correct
7 Correct 8 ms 9936 KB Output is correct
8 Correct 9 ms 10580 KB Output is correct
9 Correct 10 ms 10436 KB Output is correct
10 Correct 8 ms 10580 KB Output is correct
11 Correct 8 ms 10364 KB Output is correct
12 Correct 9 ms 11092 KB Output is correct
13 Correct 8 ms 10580 KB Output is correct
14 Correct 8 ms 10068 KB Output is correct
15 Correct 9 ms 10712 KB Output is correct
16 Correct 3 ms 2264 KB Output is correct
17 Correct 3 ms 2516 KB Output is correct
18 Correct 4 ms 2388 KB Output is correct
19 Correct 3 ms 2388 KB Output is correct
20 Correct 3 ms 2388 KB Output is correct
21 Incorrect 318 ms 20916 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11220 KB Output is correct
2 Correct 9 ms 11220 KB Output is correct
3 Correct 10 ms 11220 KB Output is correct
4 Correct 9 ms 11216 KB Output is correct
5 Correct 9 ms 11220 KB Output is correct
6 Correct 7 ms 10068 KB Output is correct
7 Correct 8 ms 9936 KB Output is correct
8 Correct 9 ms 10580 KB Output is correct
9 Correct 10 ms 10436 KB Output is correct
10 Correct 8 ms 10580 KB Output is correct
11 Correct 8 ms 10364 KB Output is correct
12 Correct 9 ms 11092 KB Output is correct
13 Correct 8 ms 10580 KB Output is correct
14 Correct 8 ms 10068 KB Output is correct
15 Correct 9 ms 10712 KB Output is correct
16 Correct 3 ms 2264 KB Output is correct
17 Correct 3 ms 2516 KB Output is correct
18 Correct 4 ms 2388 KB Output is correct
19 Correct 3 ms 2388 KB Output is correct
20 Correct 3 ms 2388 KB Output is correct
21 Incorrect 318 ms 20916 KB Output isn't correct
22 Halted 0 ms 0 KB -