Submission #946741

# Submission time Handle Problem Language Result Execution time Memory
946741 2024-03-15T01:26:11 Z Ice_man Boat (APIO16_boat) C++14
100 / 100
472 ms 8616 KB
#include <iostream>
#include <chrono>
#include <set>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>

#define maxn 1005
#define maxlog 20
#define mod 1000000007
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;

#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")

using namespace std;

std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;

double timePassed()
{
    using namespace std::chrono;
    currT = high_resolution_clock::now();
    double time = duration_cast<duration<double>>(currT - startT).count();
    return time * TIME_MULT;
}

long long m[maxn * 2];

void inv_mod()
{
    m[1] = 1;
    for(long long i = 2; i < maxn * 2; i++)
        m[i] = (mod / i) * (mod - m[mod % i]) % mod;
}


long long l[maxn], r[maxn];
long long n;
long long dp[maxn][maxn];

void read()
{
    cin >> n;

    for(long long i = 1; i <= n; i++)
        cin >> l[i] >> r[i];
}

long long ans = 0;
vector <long long> v;

void pre()
{
    for(long long i = 1; i <= n; i++)
    {
        v.pb(l[i]);
        v.pb(r[i] + 1);
    }

    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());

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

}






void calc_dp()
{
    dp[0][0] = 1;

    long long a , br , c;

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

        for(long long j = 1; j <= n; j++)
        {
            dp[i][j] = dp[i - 1][j];

            if(l[j] > i)
                continue;

            if(i >= r[j])
                continue;

            a = v[i] - v[i - 1];
            br = 1;
            c = v[i] - v[i - 1];

            for(long long k = j - 1; k > -1; k--)
            {
                dp[i][j] += dp[i - 1][k] * c;
                dp[i][j] %= mod;

                if(i >= l[k] && i < r[k])
                {
                    c *= (a + br);
                    c %= mod;

                    c *= m[br + 1];
                    c %= mod;
                    br++;
                }

            }


        }

    }

    long long ans = 0;

    for(long long i = 1; i <= n; i++)
    {
        ans += dp[v.size() - 1][i];
        ans %= mod;
    }

    cout << ans << endl;
}





int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    //startT = std::chrono::high_resolution_clock::now();

    inv_mod();

    /**for(long long i = 1; i <= 10; i++)
        cout << m[i] << " ";
    cout << endl;*/

    read();
    pre();
    calc_dp();


    return 0;
}

Compilation message

boat.cpp: In function 'void calc_dp()':
boat.cpp:91:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(long long i = 1; i < v.size(); i++)
      |                          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 3 ms 8168 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8288 KB Output is correct
11 Correct 3 ms 8300 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8168 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2536 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 3 ms 8168 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8288 KB Output is correct
11 Correct 3 ms 8300 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8168 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2536 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 191 ms 7504 KB Output is correct
22 Correct 186 ms 7596 KB Output is correct
23 Correct 164 ms 7584 KB Output is correct
24 Correct 180 ms 7504 KB Output is correct
25 Correct 183 ms 7376 KB Output is correct
26 Correct 413 ms 7320 KB Output is correct
27 Correct 421 ms 7344 KB Output is correct
28 Correct 413 ms 7332 KB Output is correct
29 Correct 408 ms 7324 KB Output is correct
30 Correct 4 ms 8280 KB Output is correct
31 Correct 4 ms 8284 KB Output is correct
32 Correct 4 ms 8280 KB Output is correct
33 Correct 4 ms 8164 KB Output is correct
34 Correct 4 ms 8284 KB Output is correct
35 Correct 4 ms 8172 KB Output is correct
36 Correct 4 ms 8284 KB Output is correct
37 Correct 4 ms 8284 KB Output is correct
38 Correct 4 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2656 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 4 ms 2652 KB Output is correct
7 Correct 4 ms 2652 KB Output is correct
8 Correct 4 ms 2652 KB Output is correct
9 Correct 4 ms 2660 KB Output is correct
10 Correct 4 ms 2652 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2660 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 3 ms 8168 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8288 KB Output is correct
11 Correct 3 ms 8300 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8168 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2536 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 191 ms 7504 KB Output is correct
22 Correct 186 ms 7596 KB Output is correct
23 Correct 164 ms 7584 KB Output is correct
24 Correct 180 ms 7504 KB Output is correct
25 Correct 183 ms 7376 KB Output is correct
26 Correct 413 ms 7320 KB Output is correct
27 Correct 421 ms 7344 KB Output is correct
28 Correct 413 ms 7332 KB Output is correct
29 Correct 408 ms 7324 KB Output is correct
30 Correct 4 ms 8280 KB Output is correct
31 Correct 4 ms 8284 KB Output is correct
32 Correct 4 ms 8280 KB Output is correct
33 Correct 4 ms 8164 KB Output is correct
34 Correct 4 ms 8284 KB Output is correct
35 Correct 4 ms 8172 KB Output is correct
36 Correct 4 ms 8284 KB Output is correct
37 Correct 4 ms 8284 KB Output is correct
38 Correct 4 ms 8284 KB Output is correct
39 Correct 2 ms 2648 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 2 ms 2656 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 4 ms 2652 KB Output is correct
45 Correct 4 ms 2652 KB Output is correct
46 Correct 4 ms 2652 KB Output is correct
47 Correct 4 ms 2660 KB Output is correct
48 Correct 4 ms 2652 KB Output is correct
49 Correct 2 ms 2396 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 2 ms 2648 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2660 KB Output is correct
55 Correct 2 ms 2652 KB Output is correct
56 Correct 2 ms 2652 KB Output is correct
57 Correct 2 ms 2652 KB Output is correct
58 Correct 2 ms 2652 KB Output is correct
59 Correct 206 ms 8276 KB Output is correct
60 Correct 194 ms 8536 KB Output is correct
61 Correct 182 ms 8276 KB Output is correct
62 Correct 208 ms 8112 KB Output is correct
63 Correct 200 ms 8616 KB Output is correct
64 Correct 470 ms 8164 KB Output is correct
65 Correct 472 ms 8536 KB Output is correct
66 Correct 469 ms 8276 KB Output is correct
67 Correct 471 ms 8360 KB Output is correct
68 Correct 469 ms 8360 KB Output is correct
69 Correct 173 ms 8360 KB Output is correct
70 Correct 174 ms 8360 KB Output is correct
71 Correct 176 ms 8532 KB Output is correct
72 Correct 183 ms 8356 KB Output is correct
73 Correct 187 ms 8276 KB Output is correct
74 Correct 41 ms 2652 KB Output is correct
75 Correct 38 ms 2716 KB Output is correct
76 Correct 40 ms 2652 KB Output is correct
77 Correct 41 ms 2652 KB Output is correct
78 Correct 41 ms 2652 KB Output is correct