Submission #730204

# Submission time Handle Problem Language Result Execution time Memory
730204 2023-04-25T11:56:48 Z josanneo22 Boat (APIO16_boat) C++17
100 / 100
458 ms 2360 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <functional>
#include <numeric>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

lint ipow(int x, int p){
	lint ret = 1, piv = x;
	while(p){
		if(p & 1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret;
}

int n, s[505], e[505];
lint inv[1005], dp[505], sum[505], dp2[505][505];
vector<int> v;

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> s[i] >> e[i];
		e[i]++;
		v.push_back(s[i]);
		v.push_back(e[i]);
	}
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	for(int i=1; i<=1000; i++){
		inv[i] = ipow(i, mod - 2);
	}
	dp[0] = 1;
	for(int i=1; i<v.size(); i++){
		int st = v[i-1], ed = v[i];
		vector<int> cnd;
		sum[0] = 1;
		for(int j=1; j<=n; j++){
			sum[j] = (sum[j-1] + dp[j]) % mod;
			if(s[j] <= st && ed <= e[j]){
				cnd.push_back(j);
			}
		}
		for(int i=1; i<=cnd.size() && i <= ed - st; i++){
			for(int j=i-1; j<cnd.size(); j++){
				if(i == 1){
					dp2[i][j] = sum[cnd[j] - 1] * (ed - st);
					if(j) dp2[i][j] += dp2[i][j-1];
					dp2[i][j] %= mod;
				}
				else{
					dp2[i][j] = (dp2[i-1][j-1] * inv[i] % mod) * (ed - st + 1 - i) + dp2[i][j-1];
					dp2[i][j] %= mod;
				}
			}
		}
		for(int i=1; i<=cnd.size() && i <= ed - st; i++){
			for(int j=i-1; j<cnd.size(); j++){
				int cnt = dp2[i][j] - (j ? dp2[i][j-1] : 0) + mod;
				cnt %= mod;
				dp[cnd[j]] += cnt;
				dp[cnd[j]] %= mod;
			}
		}
	}
	int ret= 0;
	for(int i=1; i<=n; i++){
		ret += dp[i];
		ret %= mod;
	}
	cout << ret;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for(int i=1; i<v.size(); i++){
      |               ~^~~~~~~~~
boat.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for(int i=1; i<=cnd.size() && i <= ed - st; i++){
      |                ~^~~~~~~~~~~~
boat.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    for(int j=i-1; j<cnd.size(); j++){
      |                   ~^~~~~~~~~~~
boat.cpp:79:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int i=1; i<=cnd.size() && i <= ed - st; i++){
      |                ~^~~~~~~~~~~~
boat.cpp:80:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |    for(int j=i-1; j<cnd.size(); j++){
      |                   ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 5 ms 312 KB Output is correct
3 Correct 5 ms 316 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 5 ms 340 KB Output is correct
9 Correct 6 ms 312 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 6 ms 340 KB Output is correct
12 Correct 5 ms 316 KB Output is correct
13 Correct 5 ms 320 KB Output is correct
14 Correct 5 ms 340 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 312 KB Output is correct
18 Correct 2 ms 312 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 5 ms 312 KB Output is correct
3 Correct 5 ms 316 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 5 ms 340 KB Output is correct
9 Correct 6 ms 312 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 6 ms 340 KB Output is correct
12 Correct 5 ms 316 KB Output is correct
13 Correct 5 ms 320 KB Output is correct
14 Correct 5 ms 340 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 312 KB Output is correct
18 Correct 2 ms 312 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 14 ms 340 KB Output is correct
22 Correct 14 ms 596 KB Output is correct
23 Correct 14 ms 436 KB Output is correct
24 Correct 15 ms 452 KB Output is correct
25 Correct 14 ms 460 KB Output is correct
26 Correct 15 ms 448 KB Output is correct
27 Correct 19 ms 444 KB Output is correct
28 Correct 16 ms 408 KB Output is correct
29 Correct 15 ms 484 KB Output is correct
30 Correct 5 ms 316 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 5 ms 352 KB Output is correct
34 Correct 5 ms 340 KB Output is correct
35 Correct 4 ms 316 KB Output is correct
36 Correct 5 ms 340 KB Output is correct
37 Correct 5 ms 316 KB Output is correct
38 Correct 4 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 2 ms 432 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 3 ms 436 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 6 ms 720 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 ms 724 KB Output is correct
9 Correct 5 ms 724 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 560 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 432 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 5 ms 312 KB Output is correct
3 Correct 5 ms 316 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 5 ms 340 KB Output is correct
9 Correct 6 ms 312 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 6 ms 340 KB Output is correct
12 Correct 5 ms 316 KB Output is correct
13 Correct 5 ms 320 KB Output is correct
14 Correct 5 ms 340 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 312 KB Output is correct
18 Correct 2 ms 312 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 14 ms 340 KB Output is correct
22 Correct 14 ms 596 KB Output is correct
23 Correct 14 ms 436 KB Output is correct
24 Correct 15 ms 452 KB Output is correct
25 Correct 14 ms 460 KB Output is correct
26 Correct 15 ms 448 KB Output is correct
27 Correct 19 ms 444 KB Output is correct
28 Correct 16 ms 408 KB Output is correct
29 Correct 15 ms 484 KB Output is correct
30 Correct 5 ms 316 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 5 ms 352 KB Output is correct
34 Correct 5 ms 340 KB Output is correct
35 Correct 4 ms 316 KB Output is correct
36 Correct 5 ms 340 KB Output is correct
37 Correct 5 ms 316 KB Output is correct
38 Correct 4 ms 316 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 2 ms 432 KB Output is correct
41 Correct 4 ms 468 KB Output is correct
42 Correct 3 ms 436 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 6 ms 720 KB Output is correct
45 Correct 5 ms 724 KB Output is correct
46 Correct 5 ms 724 KB Output is correct
47 Correct 5 ms 724 KB Output is correct
48 Correct 5 ms 724 KB Output is correct
49 Correct 3 ms 468 KB Output is correct
50 Correct 3 ms 468 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 2 ms 560 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 432 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
59 Correct 211 ms 1372 KB Output is correct
60 Correct 172 ms 1280 KB Output is correct
61 Correct 158 ms 1300 KB Output is correct
62 Correct 193 ms 1440 KB Output is correct
63 Correct 176 ms 1256 KB Output is correct
64 Correct 421 ms 2188 KB Output is correct
65 Correct 446 ms 2320 KB Output is correct
66 Correct 458 ms 2296 KB Output is correct
67 Correct 428 ms 2360 KB Output is correct
68 Correct 440 ms 2348 KB Output is correct
69 Correct 163 ms 1268 KB Output is correct
70 Correct 169 ms 1240 KB Output is correct
71 Correct 161 ms 1292 KB Output is correct
72 Correct 172 ms 1508 KB Output is correct
73 Correct 185 ms 1232 KB Output is correct
74 Correct 20 ms 1236 KB Output is correct
75 Correct 19 ms 1320 KB Output is correct
76 Correct 20 ms 1328 KB Output is correct
77 Correct 20 ms 1364 KB Output is correct
78 Correct 21 ms 1388 KB Output is correct