Submission #588613

# Submission time Handle Problem Language Result Execution time Memory
588613 2022-07-03T16:53:22 Z messiuuuuu Boat (APIO16_boat) C++14
100 / 100
474 ms 2392 KB
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e3 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 7;

int n, a[MAXN], b[MAXN];
vector<int> num;

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i];
        num.pb(a[i]);
        num.pb(b[i] + 1);
    }
}

int l[MAXN];
int dp[MAXN][MAXN];

void add(int& a, int b)
{
    a += b;
    if (a > MOD)
        a -= MOD;
}

int inv[MAXN];

void Solve()
{
    inv[1] = 1;
    for (int i = 2; i < MAXN; i++)
        inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD;
    sort(num.begin(), num.end());
    num.erase(unique(num.begin(), num.end()), num.end());
    for (int i = 1; i < num.size(); i++)
    {
        l[i] = num[i] - num[i - 1];
    }
    for (int i = 1; i <= n; i++)
    {
        a[i] = upper_bound(num.begin(), num.end(), a[i]) - num.begin();
        b[i] = upper_bound(num.begin(), num.end(), b[i]) - num.begin();
    }
    for (int i = 0; i < num.size(); i++)
        dp[0][i] = 1;
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = 1;
        for (int j = a[i]; j <= b[i]; j++)
        {
            dp[i][j] = (1ll * dp[i - 1][j - 1] * l[j]) % MOD;
            int cnt = 1;
            int sl = l[j] - 1;
            for (int k = i - 1; k; k--)
            {
                if (a[k] <= j && j <= b[k])
                {
                    cnt++;
                    sl = 1ll * sl * (l[j] + cnt - 2) % MOD * inv[cnt] % MOD;
                    if (!sl)
                        break;
                    add(dp[i][j], 1ll * dp[k - 1][j - 1] * sl % MOD);
                }
            }
        }

        for (int j = 1; j < num.size(); j++)
        {
            add(dp[i][j], (1ll * dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD);
        }

    }
    cout << (dp[n][(int)num.size() - 1] - 1 + MOD) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}

Compilation message

boat.cpp: In function 'void Solve()':
boat.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 1; i < num.size(); i++)
      |                     ~~^~~~~~~~~~~~
boat.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < num.size(); i++)
      |                     ~~^~~~~~~~~~~~
boat.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int j = 1; j < num.size(); j++)
      |                         ~~^~~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2260 KB Output is correct
2 Correct 6 ms 2260 KB Output is correct
3 Correct 6 ms 2260 KB Output is correct
4 Correct 6 ms 2260 KB Output is correct
5 Correct 7 ms 2260 KB Output is correct
6 Correct 6 ms 2260 KB Output is correct
7 Correct 6 ms 2260 KB Output is correct
8 Correct 6 ms 2260 KB Output is correct
9 Correct 7 ms 2296 KB Output is correct
10 Correct 6 ms 2260 KB Output is correct
11 Correct 7 ms 2260 KB Output is correct
12 Correct 6 ms 2260 KB Output is correct
13 Correct 6 ms 2260 KB Output is correct
14 Correct 6 ms 2292 KB Output is correct
15 Correct 6 ms 2260 KB Output is correct
16 Correct 2 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2260 KB Output is correct
2 Correct 6 ms 2260 KB Output is correct
3 Correct 6 ms 2260 KB Output is correct
4 Correct 6 ms 2260 KB Output is correct
5 Correct 7 ms 2260 KB Output is correct
6 Correct 6 ms 2260 KB Output is correct
7 Correct 6 ms 2260 KB Output is correct
8 Correct 6 ms 2260 KB Output is correct
9 Correct 7 ms 2296 KB Output is correct
10 Correct 6 ms 2260 KB Output is correct
11 Correct 7 ms 2260 KB Output is correct
12 Correct 6 ms 2260 KB Output is correct
13 Correct 6 ms 2260 KB Output is correct
14 Correct 6 ms 2292 KB Output is correct
15 Correct 6 ms 2260 KB Output is correct
16 Correct 2 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Correct 156 ms 2260 KB Output is correct
22 Correct 165 ms 2252 KB Output is correct
23 Correct 127 ms 2240 KB Output is correct
24 Correct 149 ms 2232 KB Output is correct
25 Correct 158 ms 2292 KB Output is correct
26 Correct 315 ms 2312 KB Output is correct
27 Correct 309 ms 2192 KB Output is correct
28 Correct 340 ms 2204 KB Output is correct
29 Correct 330 ms 2264 KB Output is correct
30 Correct 6 ms 2260 KB Output is correct
31 Correct 7 ms 2260 KB Output is correct
32 Correct 6 ms 2260 KB Output is correct
33 Correct 6 ms 2260 KB Output is correct
34 Correct 6 ms 2260 KB Output is correct
35 Correct 6 ms 2216 KB Output is correct
36 Correct 7 ms 2200 KB Output is correct
37 Correct 7 ms 2312 KB Output is correct
38 Correct 7 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 5 ms 724 KB Output is correct
7 Correct 4 ms 740 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 1 ms 712 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2260 KB Output is correct
2 Correct 6 ms 2260 KB Output is correct
3 Correct 6 ms 2260 KB Output is correct
4 Correct 6 ms 2260 KB Output is correct
5 Correct 7 ms 2260 KB Output is correct
6 Correct 6 ms 2260 KB Output is correct
7 Correct 6 ms 2260 KB Output is correct
8 Correct 6 ms 2260 KB Output is correct
9 Correct 7 ms 2296 KB Output is correct
10 Correct 6 ms 2260 KB Output is correct
11 Correct 7 ms 2260 KB Output is correct
12 Correct 6 ms 2260 KB Output is correct
13 Correct 6 ms 2260 KB Output is correct
14 Correct 6 ms 2292 KB Output is correct
15 Correct 6 ms 2260 KB Output is correct
16 Correct 2 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Correct 156 ms 2260 KB Output is correct
22 Correct 165 ms 2252 KB Output is correct
23 Correct 127 ms 2240 KB Output is correct
24 Correct 149 ms 2232 KB Output is correct
25 Correct 158 ms 2292 KB Output is correct
26 Correct 315 ms 2312 KB Output is correct
27 Correct 309 ms 2192 KB Output is correct
28 Correct 340 ms 2204 KB Output is correct
29 Correct 330 ms 2264 KB Output is correct
30 Correct 6 ms 2260 KB Output is correct
31 Correct 7 ms 2260 KB Output is correct
32 Correct 6 ms 2260 KB Output is correct
33 Correct 6 ms 2260 KB Output is correct
34 Correct 6 ms 2260 KB Output is correct
35 Correct 6 ms 2216 KB Output is correct
36 Correct 7 ms 2200 KB Output is correct
37 Correct 7 ms 2312 KB Output is correct
38 Correct 7 ms 2260 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 2 ms 716 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 5 ms 724 KB Output is correct
45 Correct 4 ms 740 KB Output is correct
46 Correct 5 ms 716 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 4 ms 724 KB Output is correct
49 Correct 2 ms 724 KB Output is correct
50 Correct 2 ms 724 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 3 ms 724 KB Output is correct
54 Correct 2 ms 716 KB Output is correct
55 Correct 2 ms 724 KB Output is correct
56 Correct 1 ms 712 KB Output is correct
57 Correct 1 ms 724 KB Output is correct
58 Correct 2 ms 724 KB Output is correct
59 Correct 215 ms 2280 KB Output is correct
60 Correct 181 ms 2192 KB Output is correct
61 Correct 169 ms 2292 KB Output is correct
62 Correct 206 ms 2252 KB Output is correct
63 Correct 186 ms 2276 KB Output is correct
64 Correct 468 ms 2268 KB Output is correct
65 Correct 469 ms 2380 KB Output is correct
66 Correct 468 ms 2392 KB Output is correct
67 Correct 474 ms 2296 KB Output is correct
68 Correct 455 ms 2224 KB Output is correct
69 Correct 173 ms 2252 KB Output is correct
70 Correct 172 ms 2308 KB Output is correct
71 Correct 176 ms 2228 KB Output is correct
72 Correct 184 ms 2312 KB Output is correct
73 Correct 184 ms 2292 KB Output is correct
74 Correct 27 ms 2260 KB Output is correct
75 Correct 26 ms 2212 KB Output is correct
76 Correct 23 ms 2292 KB Output is correct
77 Correct 23 ms 2280 KB Output is correct
78 Correct 24 ms 2304 KB Output is correct