Submission #680746

# Submission time Handle Problem Language Result Execution time Memory
680746 2023-01-11T17:03:51 Z MilosMilutinovic Boat (APIO16_boat) C++14
100 / 100
250 ms 4296 KB
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;
 
typedef long long ll;
 
const int MOD = (int)1e9 + 7;
int ckadd(int a, int b) {
	return a + b >= MOD ? a + b - MOD : a + b;
}
int ckmul(int a, int b) {
	return (a * 1LL * b) % MOD;
}
int bin_pow(int x, int k) {
	int r = 1;
	while(k) {
		if (k & 1) r = ckmul(r, x);
		x = ckmul(x, x);
		k /= 2;
	}
	return r;
}
 
const int N = 505;
int n;
int l[N];
int r[N];
int b[2 * N];
int dp[N][2 * N];
int ways[2 * N][N];
int fact[3 * N];
int inv[3 * N];
 
void init() {
	fact[0] = 1;
	for (int i = 1; i < 3 * N; i++) fact[i] = ckmul(fact[i - 1], i);
	for (int i = 0; i < 3 * N; i++) inv[i] = bin_pow(fact[i], MOD - 2);
}
int C(int n, int k) {
	if (n < k) return 0;
	return ckmul(fact[n], ckmul(inv[k], inv[n - k]));
}
 
int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
 
	init();
 
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &l[i], &r[i]);
		r[i]++;
		b[2 * i] = l[i];
		b[2 * i + 1] = r[i];
	}
	b[2 * n] = 0;
	sort(b, b + 2 * n + 1);
	int m = unique(b, b + 2 * n + 1) - b;
	for (int i = 0; i < n; i++) {
		l[i] = lower_bound(b, b + m, l[i]) - b;
		r[i] = lower_bound(b, b + m, r[i]) - b;
	}
	for (int i = 0; i < m - 1; i++) {
		int prod = 1;
		int len = b[i + 1] - b[i];
		for (int j = 1; j <= n; j++) {
			prod = ckmul(prod, len + j - 1);
			ways[i][j] = ckmul(prod, inv[j]);
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j < m; j++) dp[i][j] = ckadd(dp[i][j - 1], dp[i][j]);
		for (int v = l[i]; v < r[i]; v++) {
 			int d = b[v + 1] - b[v], c = 0;
			for (int f = i; f >= 0; f--) {
				if (v >= l[f] && v < r[f]) c++;
				dp[i + 1][v] = ckadd(dp[i + 1][v], ckmul(dp[f][v - 1], ways[v][c]));
			}
		}
	}
	for (int j = 1; j < m; j++)
		dp[n][j] = ckadd(dp[n][j], dp[n][j - 1]);
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = ckadd(ans, dp[i][m - 1]);
	printf("%d\n", ans);
 
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:95:9: warning: unused variable 'd' [-Wunused-variable]
   95 |     int d = b[v + 1] - b[v], c = 0;
      |         ^
boat.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
boat.cpp:71:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   scanf("%d%d", &l[i], &r[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4252 KB Output is correct
2 Correct 8 ms 4180 KB Output is correct
3 Correct 8 ms 4204 KB Output is correct
4 Correct 8 ms 4180 KB Output is correct
5 Correct 8 ms 4180 KB Output is correct
6 Correct 8 ms 4296 KB Output is correct
7 Correct 8 ms 4296 KB Output is correct
8 Correct 8 ms 4180 KB Output is correct
9 Correct 9 ms 4180 KB Output is correct
10 Correct 7 ms 4180 KB Output is correct
11 Correct 8 ms 4232 KB Output is correct
12 Correct 7 ms 4180 KB Output is correct
13 Correct 8 ms 4180 KB Output is correct
14 Correct 8 ms 4180 KB Output is correct
15 Correct 8 ms 4180 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 4 ms 2772 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2664 KB Output is correct
20 Correct 4 ms 2632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4252 KB Output is correct
2 Correct 8 ms 4180 KB Output is correct
3 Correct 8 ms 4204 KB Output is correct
4 Correct 8 ms 4180 KB Output is correct
5 Correct 8 ms 4180 KB Output is correct
6 Correct 8 ms 4296 KB Output is correct
7 Correct 8 ms 4296 KB Output is correct
8 Correct 8 ms 4180 KB Output is correct
9 Correct 9 ms 4180 KB Output is correct
10 Correct 7 ms 4180 KB Output is correct
11 Correct 8 ms 4232 KB Output is correct
12 Correct 7 ms 4180 KB Output is correct
13 Correct 8 ms 4180 KB Output is correct
14 Correct 8 ms 4180 KB Output is correct
15 Correct 8 ms 4180 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 4 ms 2772 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2664 KB Output is correct
20 Correct 4 ms 2632 KB Output is correct
21 Correct 157 ms 4048 KB Output is correct
22 Correct 148 ms 4104 KB Output is correct
23 Correct 144 ms 4028 KB Output is correct
24 Correct 148 ms 4060 KB Output is correct
25 Correct 164 ms 4048 KB Output is correct
26 Correct 196 ms 3964 KB Output is correct
27 Correct 204 ms 3992 KB Output is correct
28 Correct 200 ms 3924 KB Output is correct
29 Correct 212 ms 4080 KB Output is correct
30 Correct 9 ms 4180 KB Output is correct
31 Correct 9 ms 4196 KB Output is correct
32 Correct 8 ms 4236 KB Output is correct
33 Correct 9 ms 4212 KB Output is correct
34 Correct 9 ms 4216 KB Output is correct
35 Correct 9 ms 4168 KB Output is correct
36 Correct 11 ms 4200 KB Output is correct
37 Correct 10 ms 4292 KB Output is correct
38 Correct 10 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1088 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 2 ms 1088 KB Output is correct
4 Correct 4 ms 1108 KB Output is correct
5 Correct 3 ms 1088 KB Output is correct
6 Correct 3 ms 1092 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 5 ms 1088 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 2 ms 1108 KB Output is correct
13 Correct 3 ms 1112 KB Output is correct
14 Correct 2 ms 1084 KB Output is correct
15 Correct 3 ms 1108 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 3 ms 956 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4252 KB Output is correct
2 Correct 8 ms 4180 KB Output is correct
3 Correct 8 ms 4204 KB Output is correct
4 Correct 8 ms 4180 KB Output is correct
5 Correct 8 ms 4180 KB Output is correct
6 Correct 8 ms 4296 KB Output is correct
7 Correct 8 ms 4296 KB Output is correct
8 Correct 8 ms 4180 KB Output is correct
9 Correct 9 ms 4180 KB Output is correct
10 Correct 7 ms 4180 KB Output is correct
11 Correct 8 ms 4232 KB Output is correct
12 Correct 7 ms 4180 KB Output is correct
13 Correct 8 ms 4180 KB Output is correct
14 Correct 8 ms 4180 KB Output is correct
15 Correct 8 ms 4180 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 4 ms 2772 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2664 KB Output is correct
20 Correct 4 ms 2632 KB Output is correct
21 Correct 157 ms 4048 KB Output is correct
22 Correct 148 ms 4104 KB Output is correct
23 Correct 144 ms 4028 KB Output is correct
24 Correct 148 ms 4060 KB Output is correct
25 Correct 164 ms 4048 KB Output is correct
26 Correct 196 ms 3964 KB Output is correct
27 Correct 204 ms 3992 KB Output is correct
28 Correct 200 ms 3924 KB Output is correct
29 Correct 212 ms 4080 KB Output is correct
30 Correct 9 ms 4180 KB Output is correct
31 Correct 9 ms 4196 KB Output is correct
32 Correct 8 ms 4236 KB Output is correct
33 Correct 9 ms 4212 KB Output is correct
34 Correct 9 ms 4216 KB Output is correct
35 Correct 9 ms 4168 KB Output is correct
36 Correct 11 ms 4200 KB Output is correct
37 Correct 10 ms 4292 KB Output is correct
38 Correct 10 ms 4180 KB Output is correct
39 Correct 3 ms 1088 KB Output is correct
40 Correct 3 ms 1108 KB Output is correct
41 Correct 2 ms 1088 KB Output is correct
42 Correct 4 ms 1108 KB Output is correct
43 Correct 3 ms 1088 KB Output is correct
44 Correct 3 ms 1092 KB Output is correct
45 Correct 3 ms 1108 KB Output is correct
46 Correct 3 ms 1108 KB Output is correct
47 Correct 4 ms 1108 KB Output is correct
48 Correct 5 ms 1088 KB Output is correct
49 Correct 3 ms 1108 KB Output is correct
50 Correct 2 ms 1108 KB Output is correct
51 Correct 3 ms 1112 KB Output is correct
52 Correct 2 ms 1084 KB Output is correct
53 Correct 3 ms 1108 KB Output is correct
54 Correct 2 ms 852 KB Output is correct
55 Correct 2 ms 852 KB Output is correct
56 Correct 3 ms 852 KB Output is correct
57 Correct 3 ms 956 KB Output is correct
58 Correct 2 ms 852 KB Output is correct
59 Correct 168 ms 4176 KB Output is correct
60 Correct 166 ms 4212 KB Output is correct
61 Correct 153 ms 4284 KB Output is correct
62 Correct 185 ms 4172 KB Output is correct
63 Correct 160 ms 4204 KB Output is correct
64 Correct 250 ms 4292 KB Output is correct
65 Correct 220 ms 4240 KB Output is correct
66 Correct 250 ms 4280 KB Output is correct
67 Correct 230 ms 4176 KB Output is correct
68 Correct 224 ms 4204 KB Output is correct
69 Correct 126 ms 4240 KB Output is correct
70 Correct 127 ms 4288 KB Output is correct
71 Correct 132 ms 4180 KB Output is correct
72 Correct 143 ms 4172 KB Output is correct
73 Correct 150 ms 4272 KB Output is correct
74 Correct 37 ms 2560 KB Output is correct
75 Correct 38 ms 2596 KB Output is correct
76 Correct 38 ms 2636 KB Output is correct
77 Correct 38 ms 2548 KB Output is correct
78 Correct 47 ms 2660 KB Output is correct