Submission #985508

# Submission time Handle Problem Language Result Execution time Memory
985508 2024-05-18T02:10:54 Z zeta7532 Boat (APIO16_boat) C++17
100 / 100
800 ms 10640 KB
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = int;
const ll mod = 1e9+7;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)

ll modpow(long long A,ll N){
    long long res=1;
    while(N){
        if(N&1) res=res*A%mod;
        A=A*A%mod;
        N>>=1;
    }
    return res;
}

ll modinv(ll A){return modpow(A,mod-2);}

int main() {
    ll N;
    cin >> N;
    vector<ll> inv(N+1);
    rep(i,N+1) inv[i]=modinv(i);
    vector<ll> A(N),B(N);
    rep(i,N){
        cin >> A[i] >> B[i];
        B[i]++;
    }
    vector<ll> C;
    C.push_back(0),C.push_back(1);
    rep(i,N) C.push_back(A[i]),C.push_back(B[i]);
    sort(all(C));
    C.erase(unique(all(C)),C.end());
    rep(i,N) A[i]=lower_bound(all(C),A[i])-C.begin();
    rep(i,N) B[i]=lower_bound(all(C),B[i])-C.begin();
    ll M=C.size();
    vector<ll> D(M-1);
    rep(i,M-1) D[i]=C[i+1]-C[i];
    vector<vector<vector<ll>>> dp(2,vector<vector<ll>>(M,vector<ll>(N,0)));
    dp[0][0][0]=1;
    vector<vector<vector<ll>>> cum(2,vector<vector<ll>>(M,vector<ll>(N,0)));
    rep(j,M) cum[0][j][0]=1;
    rep(i,N){
        rep(j,M) rep(k,min(N,i+10)) dp[(i+1)%2][j][k]=0;
        for(ll j=A[i];j<B[i];j++){
            long long sumres=0;
            rep(k,N) sumres+=cum[i%2][j-1][k];
            sumres%=mod;
            sumres*=D[j];
            sumres%=mod;
            dp[(i+1)%2][j][0]=sumres;
            rep(k,min(N-1,i+10)){
                if(D[j]<k+2) break;
                long long res=(long long)(cum[i%2][j][k]+mod-cum[i%2][j-1][k])*(long long)(((long long)(D[j]-k-1)*(long long)(inv[k+2]))%mod);
                res%=mod;
                dp[(i+1)%2][j][k+1]=res;
            }
        }
        rep(k,min(N,i+10)){
            long long sum=0;
            rep(j,M){
                sum+=dp[(i+1)%2][j][k];
                cum[(i+1)%2][j][k]=(cum[i%2][j][k]+sum)%mod;
            }
        }
    }
    ll ans=mod-1;
    rep(k,N){
        ans+=cum[N%2][M-1][k];
        if(ans>=mod) ans-=mod;
    }
    cout << ans << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 458 ms 10444 KB Output is correct
2 Correct 464 ms 10332 KB Output is correct
3 Correct 456 ms 10440 KB Output is correct
4 Correct 452 ms 10332 KB Output is correct
5 Correct 445 ms 10328 KB Output is correct
6 Correct 446 ms 10576 KB Output is correct
7 Correct 460 ms 10436 KB Output is correct
8 Correct 448 ms 10440 KB Output is correct
9 Correct 482 ms 10440 KB Output is correct
10 Correct 449 ms 10328 KB Output is correct
11 Correct 451 ms 10580 KB Output is correct
12 Correct 502 ms 10576 KB Output is correct
13 Correct 448 ms 10440 KB Output is correct
14 Correct 457 ms 10440 KB Output is correct
15 Correct 439 ms 10436 KB Output is correct
16 Correct 85 ms 2204 KB Output is correct
17 Correct 83 ms 2136 KB Output is correct
18 Correct 79 ms 2140 KB Output is correct
19 Correct 83 ms 2348 KB Output is correct
20 Correct 82 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 10444 KB Output is correct
2 Correct 464 ms 10332 KB Output is correct
3 Correct 456 ms 10440 KB Output is correct
4 Correct 452 ms 10332 KB Output is correct
5 Correct 445 ms 10328 KB Output is correct
6 Correct 446 ms 10576 KB Output is correct
7 Correct 460 ms 10436 KB Output is correct
8 Correct 448 ms 10440 KB Output is correct
9 Correct 482 ms 10440 KB Output is correct
10 Correct 449 ms 10328 KB Output is correct
11 Correct 451 ms 10580 KB Output is correct
12 Correct 502 ms 10576 KB Output is correct
13 Correct 448 ms 10440 KB Output is correct
14 Correct 457 ms 10440 KB Output is correct
15 Correct 439 ms 10436 KB Output is correct
16 Correct 85 ms 2204 KB Output is correct
17 Correct 83 ms 2136 KB Output is correct
18 Correct 79 ms 2140 KB Output is correct
19 Correct 83 ms 2348 KB Output is correct
20 Correct 82 ms 2140 KB Output is correct
21 Correct 431 ms 9564 KB Output is correct
22 Correct 432 ms 9664 KB Output is correct
23 Correct 481 ms 9280 KB Output is correct
24 Correct 416 ms 9440 KB Output is correct
25 Correct 438 ms 9472 KB Output is correct
26 Correct 407 ms 9240 KB Output is correct
27 Correct 421 ms 9552 KB Output is correct
28 Correct 419 ms 9220 KB Output is correct
29 Correct 409 ms 9176 KB Output is correct
30 Correct 448 ms 10408 KB Output is correct
31 Correct 442 ms 10424 KB Output is correct
32 Correct 446 ms 10576 KB Output is correct
33 Correct 471 ms 10580 KB Output is correct
34 Correct 467 ms 10400 KB Output is correct
35 Correct 492 ms 10408 KB Output is correct
36 Correct 551 ms 10408 KB Output is correct
37 Correct 454 ms 10404 KB Output is correct
38 Correct 453 ms 10328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 860 KB Output is correct
2 Correct 6 ms 860 KB Output is correct
3 Correct 6 ms 692 KB Output is correct
4 Correct 7 ms 880 KB Output is correct
5 Correct 7 ms 860 KB Output is correct
6 Correct 8 ms 860 KB Output is correct
7 Correct 7 ms 860 KB Output is correct
8 Correct 7 ms 856 KB Output is correct
9 Correct 7 ms 856 KB Output is correct
10 Correct 10 ms 692 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 6 ms 872 KB Output is correct
13 Correct 8 ms 860 KB Output is correct
14 Correct 6 ms 872 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 10444 KB Output is correct
2 Correct 464 ms 10332 KB Output is correct
3 Correct 456 ms 10440 KB Output is correct
4 Correct 452 ms 10332 KB Output is correct
5 Correct 445 ms 10328 KB Output is correct
6 Correct 446 ms 10576 KB Output is correct
7 Correct 460 ms 10436 KB Output is correct
8 Correct 448 ms 10440 KB Output is correct
9 Correct 482 ms 10440 KB Output is correct
10 Correct 449 ms 10328 KB Output is correct
11 Correct 451 ms 10580 KB Output is correct
12 Correct 502 ms 10576 KB Output is correct
13 Correct 448 ms 10440 KB Output is correct
14 Correct 457 ms 10440 KB Output is correct
15 Correct 439 ms 10436 KB Output is correct
16 Correct 85 ms 2204 KB Output is correct
17 Correct 83 ms 2136 KB Output is correct
18 Correct 79 ms 2140 KB Output is correct
19 Correct 83 ms 2348 KB Output is correct
20 Correct 82 ms 2140 KB Output is correct
21 Correct 431 ms 9564 KB Output is correct
22 Correct 432 ms 9664 KB Output is correct
23 Correct 481 ms 9280 KB Output is correct
24 Correct 416 ms 9440 KB Output is correct
25 Correct 438 ms 9472 KB Output is correct
26 Correct 407 ms 9240 KB Output is correct
27 Correct 421 ms 9552 KB Output is correct
28 Correct 419 ms 9220 KB Output is correct
29 Correct 409 ms 9176 KB Output is correct
30 Correct 448 ms 10408 KB Output is correct
31 Correct 442 ms 10424 KB Output is correct
32 Correct 446 ms 10576 KB Output is correct
33 Correct 471 ms 10580 KB Output is correct
34 Correct 467 ms 10400 KB Output is correct
35 Correct 492 ms 10408 KB Output is correct
36 Correct 551 ms 10408 KB Output is correct
37 Correct 454 ms 10404 KB Output is correct
38 Correct 453 ms 10328 KB Output is correct
39 Correct 7 ms 860 KB Output is correct
40 Correct 6 ms 860 KB Output is correct
41 Correct 6 ms 692 KB Output is correct
42 Correct 7 ms 880 KB Output is correct
43 Correct 7 ms 860 KB Output is correct
44 Correct 8 ms 860 KB Output is correct
45 Correct 7 ms 860 KB Output is correct
46 Correct 7 ms 856 KB Output is correct
47 Correct 7 ms 856 KB Output is correct
48 Correct 10 ms 692 KB Output is correct
49 Correct 7 ms 860 KB Output is correct
50 Correct 6 ms 872 KB Output is correct
51 Correct 8 ms 860 KB Output is correct
52 Correct 6 ms 872 KB Output is correct
53 Correct 6 ms 860 KB Output is correct
54 Correct 3 ms 604 KB Output is correct
55 Correct 3 ms 604 KB Output is correct
56 Correct 3 ms 604 KB Output is correct
57 Correct 3 ms 604 KB Output is correct
58 Correct 3 ms 604 KB Output is correct
59 Correct 677 ms 10448 KB Output is correct
60 Correct 637 ms 10444 KB Output is correct
61 Correct 634 ms 10640 KB Output is correct
62 Correct 646 ms 10576 KB Output is correct
63 Correct 667 ms 10576 KB Output is correct
64 Correct 762 ms 10436 KB Output is correct
65 Correct 800 ms 10436 KB Output is correct
66 Correct 779 ms 10584 KB Output is correct
67 Correct 741 ms 10440 KB Output is correct
68 Correct 746 ms 10328 KB Output is correct
69 Correct 616 ms 10580 KB Output is correct
70 Correct 640 ms 10332 KB Output is correct
71 Correct 662 ms 10332 KB Output is correct
72 Correct 614 ms 10328 KB Output is correct
73 Correct 648 ms 10580 KB Output is correct
74 Correct 102 ms 2252 KB Output is correct
75 Correct 104 ms 2316 KB Output is correct
76 Correct 104 ms 2140 KB Output is correct
77 Correct 101 ms 2228 KB Output is correct
78 Correct 101 ms 2136 KB Output is correct