Submission #866290

# Submission time Handle Problem Language Result Execution time Memory
866290 2023-10-25T19:07:32 Z Dec0Dedd Boat (APIO16_boat) C++14
100 / 100
420 ms 4448 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 510;
const int MOD = 1e9+7;

ll a[N], b[N], l[2*N+1], dp[N][2*N+1], iv[N], n;

int main() {
    cin>>n;

    iv[1]=1;
    for (int i=2; i<N; ++i) iv[i]=(iv[MOD%i]*(MOD-MOD/i))%MOD;

    vector<int> v;
    for (int i=1; i<=n; ++i) {
        cin>>a[i]>>b[i];
        v.push_back(a[i]), v.push_back(b[i]+1);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    int sz=v.size();
    for (int i=1; i<=n; ++i) {
        a[i]=upper_bound(v.begin(), v.end(), a[i])-v.begin();
        b[i]=upper_bound(v.begin(), v.end(), b[i])-v.begin();
    }

    for (int i=1; i<sz; ++i) l[i]=v[i]-v[i-1], dp[0][i]=1;
    dp[0][0]=1;

    for (int i=1; i<=n; ++i) {
        for (int j=a[i]; j<=b[i]; ++j) {
            dp[i][j]=(1ll*l[j]*dp[i-1][j-1])%MOD;
            ll c=1, x=l[j]-1;
            for (int k=i-1; k>0; --k) {
                if (a[k] > j || b[k] < j) continue;
                ++c;
                (x=(1ll*x*(l[j]+c-2)%MOD)*iv[c])%=MOD;
                if (x == 0) break;
                (dp[i][j]+=1ll*dp[k-1][j-1]*x)%=MOD;
            }
        } dp[i][0]=1;
        for (int j=1; j<sz; ++j) dp[i][j]=(1ll*dp[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+MOD)%MOD;
    } cout<<(dp[n][sz-1]-1+MOD)%MOD<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4444 KB Output is correct
2 Correct 5 ms 4308 KB Output is correct
3 Correct 5 ms 4296 KB Output is correct
4 Correct 5 ms 4252 KB Output is correct
5 Correct 5 ms 4444 KB Output is correct
6 Correct 4 ms 4292 KB Output is correct
7 Correct 4 ms 4292 KB Output is correct
8 Correct 5 ms 4440 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 5 ms 4352 KB Output is correct
11 Correct 4 ms 4284 KB Output is correct
12 Correct 4 ms 4444 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 5 ms 4440 KB Output is correct
15 Correct 5 ms 4444 KB Output is correct
16 Correct 2 ms 3556 KB Output is correct
17 Correct 2 ms 3676 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4444 KB Output is correct
2 Correct 5 ms 4308 KB Output is correct
3 Correct 5 ms 4296 KB Output is correct
4 Correct 5 ms 4252 KB Output is correct
5 Correct 5 ms 4444 KB Output is correct
6 Correct 4 ms 4292 KB Output is correct
7 Correct 4 ms 4292 KB Output is correct
8 Correct 5 ms 4440 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 5 ms 4352 KB Output is correct
11 Correct 4 ms 4284 KB Output is correct
12 Correct 4 ms 4444 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 5 ms 4440 KB Output is correct
15 Correct 5 ms 4444 KB Output is correct
16 Correct 2 ms 3556 KB Output is correct
17 Correct 2 ms 3676 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 140 ms 4376 KB Output is correct
22 Correct 137 ms 4316 KB Output is correct
23 Correct 125 ms 4436 KB Output is correct
24 Correct 137 ms 4256 KB Output is correct
25 Correct 141 ms 4432 KB Output is correct
26 Correct 284 ms 4436 KB Output is correct
27 Correct 281 ms 4432 KB Output is correct
28 Correct 295 ms 4400 KB Output is correct
29 Correct 300 ms 4392 KB Output is correct
30 Correct 5 ms 4444 KB Output is correct
31 Correct 5 ms 4276 KB Output is correct
32 Correct 5 ms 4444 KB Output is correct
33 Correct 5 ms 4448 KB Output is correct
34 Correct 5 ms 4444 KB Output is correct
35 Correct 5 ms 4252 KB Output is correct
36 Correct 5 ms 4444 KB Output is correct
37 Correct 6 ms 4248 KB Output is correct
38 Correct 5 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2592 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 4 ms 2396 KB Output is correct
7 Correct 4 ms 2396 KB Output is correct
8 Correct 4 ms 2396 KB Output is correct
9 Correct 4 ms 2596 KB Output is correct
10 Correct 4 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 2400 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4444 KB Output is correct
2 Correct 5 ms 4308 KB Output is correct
3 Correct 5 ms 4296 KB Output is correct
4 Correct 5 ms 4252 KB Output is correct
5 Correct 5 ms 4444 KB Output is correct
6 Correct 4 ms 4292 KB Output is correct
7 Correct 4 ms 4292 KB Output is correct
8 Correct 5 ms 4440 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 5 ms 4352 KB Output is correct
11 Correct 4 ms 4284 KB Output is correct
12 Correct 4 ms 4444 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 5 ms 4440 KB Output is correct
15 Correct 5 ms 4444 KB Output is correct
16 Correct 2 ms 3556 KB Output is correct
17 Correct 2 ms 3676 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 140 ms 4376 KB Output is correct
22 Correct 137 ms 4316 KB Output is correct
23 Correct 125 ms 4436 KB Output is correct
24 Correct 137 ms 4256 KB Output is correct
25 Correct 141 ms 4432 KB Output is correct
26 Correct 284 ms 4436 KB Output is correct
27 Correct 281 ms 4432 KB Output is correct
28 Correct 295 ms 4400 KB Output is correct
29 Correct 300 ms 4392 KB Output is correct
30 Correct 5 ms 4444 KB Output is correct
31 Correct 5 ms 4276 KB Output is correct
32 Correct 5 ms 4444 KB Output is correct
33 Correct 5 ms 4448 KB Output is correct
34 Correct 5 ms 4444 KB Output is correct
35 Correct 5 ms 4252 KB Output is correct
36 Correct 5 ms 4444 KB Output is correct
37 Correct 6 ms 4248 KB Output is correct
38 Correct 5 ms 4436 KB Output is correct
39 Correct 2 ms 2592 KB Output is correct
40 Correct 2 ms 2392 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2396 KB Output is correct
43 Correct 2 ms 2396 KB Output is correct
44 Correct 4 ms 2396 KB Output is correct
45 Correct 4 ms 2396 KB Output is correct
46 Correct 4 ms 2396 KB Output is correct
47 Correct 4 ms 2596 KB Output is correct
48 Correct 4 ms 2396 KB Output is correct
49 Correct 2 ms 2396 KB Output is correct
50 Correct 2 ms 2396 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 2 ms 2396 KB Output is correct
53 Correct 2 ms 2396 KB Output is correct
54 Correct 1 ms 2400 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2596 KB Output is correct
59 Correct 184 ms 4232 KB Output is correct
60 Correct 165 ms 4260 KB Output is correct
61 Correct 156 ms 4448 KB Output is correct
62 Correct 187 ms 4432 KB Output is correct
63 Correct 174 ms 4436 KB Output is correct
64 Correct 419 ms 4256 KB Output is correct
65 Correct 417 ms 4432 KB Output is correct
66 Correct 420 ms 4344 KB Output is correct
67 Correct 417 ms 4236 KB Output is correct
68 Correct 419 ms 4324 KB Output is correct
69 Correct 162 ms 4428 KB Output is correct
70 Correct 167 ms 4320 KB Output is correct
71 Correct 166 ms 4252 KB Output is correct
72 Correct 171 ms 4432 KB Output is correct
73 Correct 185 ms 4304 KB Output is correct
74 Correct 21 ms 3672 KB Output is correct
75 Correct 19 ms 3752 KB Output is correct
76 Correct 20 ms 3676 KB Output is correct
77 Correct 21 ms 3672 KB Output is correct
78 Correct 22 ms 3676 KB Output is correct