# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
832878 |
2023-08-21T16:11:05 Z |
caganyanmaz |
Boat (APIO16_boat) |
C++17 |
|
1864 ms |
43680 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int int64_t
#define pb push_back
using namespace std;
//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
constexpr static int MXN = 1000;
constexpr static int MXR = 2000;
int n;
vector<int> a, b;
vector<int> ranges;
vector<vector<int>> dp(MXR, vector<int>(MXN, 0)); // Schools passed, last range, count in last range
vector<vector<int>> old_dp(MXR, vector<int>(MXN, 0));
int sums[MXN][MXN]; // last range
constexpr static int MOD = 1e9 + 7;
static inline int add(int a, int b) { return (a+b) % MOD; }
static inline int mul(int64_t a, int64_t b) { return (a*b) % MOD; }
static inline int pow(int a, int b)
{
int res = 1;
while (b)
{
if (b&1)
{
res = mul(a, res);
b--;
}
else
{
a = mul(a, a);
b >>= 1;
}
}
return res;
}
static inline int _div(int a, int b) { return mul(a, pow(b, MOD-2)); }
int C[MXR][MXN];
int p[MXN];
int32_t main()
{
cin >> n;
p[0] = 1;
for (int i = 1; i < n; i++)
p[i] = mul(i, p[i-1]);
a.resize(n, 0), b.resize(n, 0);
debug("A");
for (int i = 0; i < n; i++)
{
cin >> a[i] >> b[i];
b[i]++;
}
debug("b");
vector<int> c;
for (int i = 0; i < n; i++)
c.pb(a[i]);
for (int i = 0; i < n; i++)
c.pb(b[i]);
debug("A");
sort(c.begin(), c.end());
auto last = unique(c.begin(), c.end());
c.erase(last, c.end());
int rn = c.size();
for (int i = 0; i < c.size()-1; i++)
ranges.pb(c[i+1] - c[i]);
debug("B");
for (int i = 0; i < rn; i++)
{
int pf = 1;
for (int j = 0; j <= n; j++)
{
C[i][j] = pf;
pf = mul(pf, ranges[i]-j);
pf = _div(pf, j+1);
if (ranges[i] < j)
C[i][j] = 0;
debug(i, j, C[i][j]);
}
}
debug("D");
debug(a, b);
for (int& i : a)
i = lower_bound(c.begin(), c.end(), i) - c.begin();
for (int& i : b)
i = lower_bound(c.begin(), c.end(), i) - c.begin();
debug(a, b);
for (int j = 0; j < rn; j++)
old_dp[j][0] = 1;
for (int i = 1; i <= n; i++) // Current node
{
for (int j = 0; j < rn; j++) // Current range
{
dp[j][0] = 1;
for (int k = 1; k <= n; k++) // Current count
{
dp[j][k] = 0;
if (a[i-1] <= j && b[i-1] > j)
{
if (j > 0 && k == 1)
dp[j][k] = add(dp[j][k], sums[i-1][j-1]); // Starting with it
dp[j][k] = add(dp[j][k], old_dp[j][k-1]); // Including it
debug(i, j, k);
}
dp[j][k] = add(dp[j][k], old_dp[j][k]); // Not including it
debug(i, j, k, dp[j][k]);
}
}
for (int j = 0; j < rn; j++)
{
if (j > 0)
sums[i][j] = add(sums[i][j], sums[i][j-1]);
debug(sums[i][j]);
for (int k = 1; k <= n; k++)
{
sums[i][j] = add(sums[i][j], mul(dp[j][k], C[j][k]));
}
debug(i, j, sums[i][j]);
}
swap(old_dp, dp);
}
int res = 0;
for (int i = 0; i < rn; i++)
{
for (int j = 1; j <= n; j++)
{
debug(i, j, old_dp[i][j]);
res = add(res, mul(old_dp[i][j], C[i][j]));
}
}
cout << res << "\n";
}
Compilation message
boat.cpp: In function 'int32_t main()':
boat.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i = 0; i < c.size()-1; i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1654 ms |
43536 KB |
Output is correct |
2 |
Correct |
1622 ms |
43512 KB |
Output is correct |
3 |
Correct |
1680 ms |
43584 KB |
Output is correct |
4 |
Correct |
1638 ms |
43544 KB |
Output is correct |
5 |
Correct |
1633 ms |
43644 KB |
Output is correct |
6 |
Correct |
1621 ms |
43504 KB |
Output is correct |
7 |
Correct |
1661 ms |
43668 KB |
Output is correct |
8 |
Correct |
1684 ms |
43596 KB |
Output is correct |
9 |
Correct |
1637 ms |
43680 KB |
Output is correct |
10 |
Correct |
1681 ms |
43540 KB |
Output is correct |
11 |
Correct |
1656 ms |
43648 KB |
Output is correct |
12 |
Correct |
1656 ms |
43464 KB |
Output is correct |
13 |
Correct |
1639 ms |
43592 KB |
Output is correct |
14 |
Correct |
1700 ms |
43616 KB |
Output is correct |
15 |
Correct |
1634 ms |
43468 KB |
Output is correct |
16 |
Correct |
267 ms |
35756 KB |
Output is correct |
17 |
Correct |
289 ms |
35928 KB |
Output is correct |
18 |
Correct |
295 ms |
35884 KB |
Output is correct |
19 |
Correct |
290 ms |
35948 KB |
Output is correct |
20 |
Correct |
280 ms |
35884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1654 ms |
43536 KB |
Output is correct |
2 |
Correct |
1622 ms |
43512 KB |
Output is correct |
3 |
Correct |
1680 ms |
43584 KB |
Output is correct |
4 |
Correct |
1638 ms |
43544 KB |
Output is correct |
5 |
Correct |
1633 ms |
43644 KB |
Output is correct |
6 |
Correct |
1621 ms |
43504 KB |
Output is correct |
7 |
Correct |
1661 ms |
43668 KB |
Output is correct |
8 |
Correct |
1684 ms |
43596 KB |
Output is correct |
9 |
Correct |
1637 ms |
43680 KB |
Output is correct |
10 |
Correct |
1681 ms |
43540 KB |
Output is correct |
11 |
Correct |
1656 ms |
43648 KB |
Output is correct |
12 |
Correct |
1656 ms |
43464 KB |
Output is correct |
13 |
Correct |
1639 ms |
43592 KB |
Output is correct |
14 |
Correct |
1700 ms |
43616 KB |
Output is correct |
15 |
Correct |
1634 ms |
43468 KB |
Output is correct |
16 |
Correct |
267 ms |
35756 KB |
Output is correct |
17 |
Correct |
289 ms |
35928 KB |
Output is correct |
18 |
Correct |
295 ms |
35884 KB |
Output is correct |
19 |
Correct |
290 ms |
35948 KB |
Output is correct |
20 |
Correct |
280 ms |
35884 KB |
Output is correct |
21 |
Correct |
1560 ms |
42848 KB |
Output is correct |
22 |
Correct |
1584 ms |
42832 KB |
Output is correct |
23 |
Correct |
1574 ms |
42792 KB |
Output is correct |
24 |
Correct |
1569 ms |
42748 KB |
Output is correct |
25 |
Correct |
1556 ms |
42696 KB |
Output is correct |
26 |
Correct |
1610 ms |
42584 KB |
Output is correct |
27 |
Correct |
1634 ms |
42628 KB |
Output is correct |
28 |
Correct |
1547 ms |
42484 KB |
Output is correct |
29 |
Correct |
1567 ms |
42460 KB |
Output is correct |
30 |
Correct |
1675 ms |
43448 KB |
Output is correct |
31 |
Correct |
1634 ms |
43504 KB |
Output is correct |
32 |
Correct |
1655 ms |
43560 KB |
Output is correct |
33 |
Correct |
1657 ms |
43512 KB |
Output is correct |
34 |
Correct |
1644 ms |
43424 KB |
Output is correct |
35 |
Correct |
1649 ms |
43408 KB |
Output is correct |
36 |
Correct |
1683 ms |
43496 KB |
Output is correct |
37 |
Correct |
1616 ms |
43404 KB |
Output is correct |
38 |
Correct |
1594 ms |
43488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
33244 KB |
Output is correct |
2 |
Correct |
31 ms |
33272 KB |
Output is correct |
3 |
Correct |
30 ms |
33272 KB |
Output is correct |
4 |
Correct |
30 ms |
33268 KB |
Output is correct |
5 |
Correct |
31 ms |
33228 KB |
Output is correct |
6 |
Correct |
31 ms |
33236 KB |
Output is correct |
7 |
Correct |
31 ms |
33268 KB |
Output is correct |
8 |
Correct |
32 ms |
33260 KB |
Output is correct |
9 |
Correct |
31 ms |
33228 KB |
Output is correct |
10 |
Correct |
31 ms |
33188 KB |
Output is correct |
11 |
Correct |
32 ms |
33252 KB |
Output is correct |
12 |
Correct |
29 ms |
33256 KB |
Output is correct |
13 |
Correct |
34 ms |
33264 KB |
Output is correct |
14 |
Correct |
30 ms |
33184 KB |
Output is correct |
15 |
Correct |
31 ms |
33268 KB |
Output is correct |
16 |
Correct |
25 ms |
32712 KB |
Output is correct |
17 |
Correct |
24 ms |
32776 KB |
Output is correct |
18 |
Correct |
25 ms |
32744 KB |
Output is correct |
19 |
Correct |
26 ms |
32812 KB |
Output is correct |
20 |
Correct |
24 ms |
32744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1654 ms |
43536 KB |
Output is correct |
2 |
Correct |
1622 ms |
43512 KB |
Output is correct |
3 |
Correct |
1680 ms |
43584 KB |
Output is correct |
4 |
Correct |
1638 ms |
43544 KB |
Output is correct |
5 |
Correct |
1633 ms |
43644 KB |
Output is correct |
6 |
Correct |
1621 ms |
43504 KB |
Output is correct |
7 |
Correct |
1661 ms |
43668 KB |
Output is correct |
8 |
Correct |
1684 ms |
43596 KB |
Output is correct |
9 |
Correct |
1637 ms |
43680 KB |
Output is correct |
10 |
Correct |
1681 ms |
43540 KB |
Output is correct |
11 |
Correct |
1656 ms |
43648 KB |
Output is correct |
12 |
Correct |
1656 ms |
43464 KB |
Output is correct |
13 |
Correct |
1639 ms |
43592 KB |
Output is correct |
14 |
Correct |
1700 ms |
43616 KB |
Output is correct |
15 |
Correct |
1634 ms |
43468 KB |
Output is correct |
16 |
Correct |
267 ms |
35756 KB |
Output is correct |
17 |
Correct |
289 ms |
35928 KB |
Output is correct |
18 |
Correct |
295 ms |
35884 KB |
Output is correct |
19 |
Correct |
290 ms |
35948 KB |
Output is correct |
20 |
Correct |
280 ms |
35884 KB |
Output is correct |
21 |
Correct |
1560 ms |
42848 KB |
Output is correct |
22 |
Correct |
1584 ms |
42832 KB |
Output is correct |
23 |
Correct |
1574 ms |
42792 KB |
Output is correct |
24 |
Correct |
1569 ms |
42748 KB |
Output is correct |
25 |
Correct |
1556 ms |
42696 KB |
Output is correct |
26 |
Correct |
1610 ms |
42584 KB |
Output is correct |
27 |
Correct |
1634 ms |
42628 KB |
Output is correct |
28 |
Correct |
1547 ms |
42484 KB |
Output is correct |
29 |
Correct |
1567 ms |
42460 KB |
Output is correct |
30 |
Correct |
1675 ms |
43448 KB |
Output is correct |
31 |
Correct |
1634 ms |
43504 KB |
Output is correct |
32 |
Correct |
1655 ms |
43560 KB |
Output is correct |
33 |
Correct |
1657 ms |
43512 KB |
Output is correct |
34 |
Correct |
1644 ms |
43424 KB |
Output is correct |
35 |
Correct |
1649 ms |
43408 KB |
Output is correct |
36 |
Correct |
1683 ms |
43496 KB |
Output is correct |
37 |
Correct |
1616 ms |
43404 KB |
Output is correct |
38 |
Correct |
1594 ms |
43488 KB |
Output is correct |
39 |
Correct |
33 ms |
33244 KB |
Output is correct |
40 |
Correct |
31 ms |
33272 KB |
Output is correct |
41 |
Correct |
30 ms |
33272 KB |
Output is correct |
42 |
Correct |
30 ms |
33268 KB |
Output is correct |
43 |
Correct |
31 ms |
33228 KB |
Output is correct |
44 |
Correct |
31 ms |
33236 KB |
Output is correct |
45 |
Correct |
31 ms |
33268 KB |
Output is correct |
46 |
Correct |
32 ms |
33260 KB |
Output is correct |
47 |
Correct |
31 ms |
33228 KB |
Output is correct |
48 |
Correct |
31 ms |
33188 KB |
Output is correct |
49 |
Correct |
32 ms |
33252 KB |
Output is correct |
50 |
Correct |
29 ms |
33256 KB |
Output is correct |
51 |
Correct |
34 ms |
33264 KB |
Output is correct |
52 |
Correct |
30 ms |
33184 KB |
Output is correct |
53 |
Correct |
31 ms |
33268 KB |
Output is correct |
54 |
Correct |
25 ms |
32712 KB |
Output is correct |
55 |
Correct |
24 ms |
32776 KB |
Output is correct |
56 |
Correct |
25 ms |
32744 KB |
Output is correct |
57 |
Correct |
26 ms |
32812 KB |
Output is correct |
58 |
Correct |
24 ms |
32744 KB |
Output is correct |
59 |
Correct |
1790 ms |
43440 KB |
Output is correct |
60 |
Correct |
1774 ms |
43572 KB |
Output is correct |
61 |
Correct |
1747 ms |
43480 KB |
Output is correct |
62 |
Correct |
1787 ms |
43508 KB |
Output is correct |
63 |
Correct |
1787 ms |
43472 KB |
Output is correct |
64 |
Correct |
1813 ms |
43488 KB |
Output is correct |
65 |
Correct |
1815 ms |
43548 KB |
Output is correct |
66 |
Correct |
1796 ms |
43520 KB |
Output is correct |
67 |
Correct |
1838 ms |
43504 KB |
Output is correct |
68 |
Correct |
1864 ms |
43536 KB |
Output is correct |
69 |
Correct |
1730 ms |
43520 KB |
Output is correct |
70 |
Correct |
1750 ms |
43544 KB |
Output is correct |
71 |
Correct |
1747 ms |
43484 KB |
Output is correct |
72 |
Correct |
1731 ms |
43476 KB |
Output is correct |
73 |
Correct |
1766 ms |
43508 KB |
Output is correct |
74 |
Correct |
299 ms |
35772 KB |
Output is correct |
75 |
Correct |
310 ms |
35948 KB |
Output is correct |
76 |
Correct |
310 ms |
35884 KB |
Output is correct |
77 |
Correct |
309 ms |
35912 KB |
Output is correct |
78 |
Correct |
307 ms |
35944 KB |
Output is correct |