Submission #598908

# Submission time Handle Problem Language Result Execution time Memory
598908 2022-07-19T07:34:16 Z radal Boat (APIO16_boat) C++17
100 / 100
1723 ms 4400 KB
#include <bits/stdc++.h>
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
//#pragma GCC optimize("unroll-loops")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 5e2+20,mod = 1e9+7 ,inf = 1e9+10,maxm = (1 << 10)+10;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    if (a+b < 0) return a+b+mod;
    return a+b;
}
 
inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k >>= 1;
    } 
    return z;
}
int dp[2][2*N][N],sum[2][2*N];
int a[N],b[N],n,inv[N*2];
int main(){
    vector<int> ve;
    cin >> n;
    ve.reserve(2*n);
    rep(i,1,n+1){
        cin >> a[i] >> b[i];
        b[i]++;
        ve.pb(a[i]);
        ve.pb(b[i]);
    }
    sort(all(ve));
    rep(i,1,n+1){
        a[i] = lower_bound(all(ve),a[i])-ve.begin();
        b[i] = lower_bound(all(ve),b[i])-ve.begin();
    }
    int nn = 2*n+1;
    rep(i,0,n+2) inv[i] = poww(i,mod-2);
    rep(i,1,n+1){
        bool f = (i&1);
        rep(j,0,nn){
            sum[f][j] = 0;
            rep(k,1,n+1){
                if (k > i) break;
                dp[f][j][k] = dp[1-f][j][k];
                if (j < a[i] || j >= b[i]){
                    sum[f][j] = (sum[f][j]+dp[f][j][k])%mod;
                    continue;
                }
                if (k > 1){
                    dp[f][j][k] = (dp[f][j][k]+1ll*dp[1-f][j][k-1]*inv[k]%mod*(ve[j+1]-ve[j]-k+1)%mod)%mod;
                }
                else{
                    dp[f][j][k] = (dp[f][j][k]+ve[j+1]-ve[j])%mod;
                    rep(g,0,j){
                        dp[f][j][k] = (dp[f][j][k]+1ll*(ve[j+1]-ve[j])*sum[1-f][g]%mod)%mod;
                    }
                }
                sum[f][j] = (sum[f][j]+dp[f][j][k])%mod;
            }
        }
    }
    bool f = n%2;
    int ans = 0;
    rep(i,0,nn){
        ans = (ans+sum[f][i])%mod;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 733 ms 4392 KB Output is correct
2 Correct 754 ms 4392 KB Output is correct
3 Correct 746 ms 4392 KB Output is correct
4 Correct 760 ms 4392 KB Output is correct
5 Correct 785 ms 4388 KB Output is correct
6 Correct 798 ms 4308 KB Output is correct
7 Correct 806 ms 4392 KB Output is correct
8 Correct 805 ms 4308 KB Output is correct
9 Correct 817 ms 4396 KB Output is correct
10 Correct 856 ms 4392 KB Output is correct
11 Correct 785 ms 4392 KB Output is correct
12 Correct 812 ms 4388 KB Output is correct
13 Correct 833 ms 4392 KB Output is correct
14 Correct 827 ms 4388 KB Output is correct
15 Correct 792 ms 4392 KB Output is correct
16 Correct 875 ms 4392 KB Output is correct
17 Correct 1053 ms 4388 KB Output is correct
18 Correct 835 ms 4388 KB Output is correct
19 Correct 842 ms 4388 KB Output is correct
20 Correct 843 ms 4388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 733 ms 4392 KB Output is correct
2 Correct 754 ms 4392 KB Output is correct
3 Correct 746 ms 4392 KB Output is correct
4 Correct 760 ms 4392 KB Output is correct
5 Correct 785 ms 4388 KB Output is correct
6 Correct 798 ms 4308 KB Output is correct
7 Correct 806 ms 4392 KB Output is correct
8 Correct 805 ms 4308 KB Output is correct
9 Correct 817 ms 4396 KB Output is correct
10 Correct 856 ms 4392 KB Output is correct
11 Correct 785 ms 4392 KB Output is correct
12 Correct 812 ms 4388 KB Output is correct
13 Correct 833 ms 4392 KB Output is correct
14 Correct 827 ms 4388 KB Output is correct
15 Correct 792 ms 4392 KB Output is correct
16 Correct 875 ms 4392 KB Output is correct
17 Correct 1053 ms 4388 KB Output is correct
18 Correct 835 ms 4388 KB Output is correct
19 Correct 842 ms 4388 KB Output is correct
20 Correct 843 ms 4388 KB Output is correct
21 Correct 1502 ms 4400 KB Output is correct
22 Correct 1338 ms 4388 KB Output is correct
23 Correct 1327 ms 4388 KB Output is correct
24 Correct 1405 ms 4388 KB Output is correct
25 Correct 1370 ms 4392 KB Output is correct
26 Correct 1723 ms 4392 KB Output is correct
27 Correct 1672 ms 4388 KB Output is correct
28 Correct 1654 ms 4384 KB Output is correct
29 Correct 1688 ms 4384 KB Output is correct
30 Correct 874 ms 4388 KB Output is correct
31 Correct 799 ms 4388 KB Output is correct
32 Correct 757 ms 4388 KB Output is correct
33 Correct 775 ms 4392 KB Output is correct
34 Correct 820 ms 4388 KB Output is correct
35 Correct 832 ms 4388 KB Output is correct
36 Correct 756 ms 4392 KB Output is correct
37 Correct 795 ms 4396 KB Output is correct
38 Correct 799 ms 4396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1108 KB Output is correct
2 Correct 10 ms 1080 KB Output is correct
3 Correct 11 ms 1108 KB Output is correct
4 Correct 12 ms 1108 KB Output is correct
5 Correct 15 ms 1108 KB Output is correct
6 Correct 13 ms 1156 KB Output is correct
7 Correct 14 ms 1148 KB Output is correct
8 Correct 14 ms 1152 KB Output is correct
9 Correct 13 ms 1152 KB Output is correct
10 Correct 13 ms 1108 KB Output is correct
11 Correct 11 ms 1108 KB Output is correct
12 Correct 12 ms 1148 KB Output is correct
13 Correct 11 ms 1108 KB Output is correct
14 Correct 10 ms 1108 KB Output is correct
15 Correct 12 ms 1108 KB Output is correct
16 Correct 12 ms 1152 KB Output is correct
17 Correct 11 ms 1108 KB Output is correct
18 Correct 11 ms 1152 KB Output is correct
19 Correct 11 ms 1108 KB Output is correct
20 Correct 13 ms 1084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 733 ms 4392 KB Output is correct
2 Correct 754 ms 4392 KB Output is correct
3 Correct 746 ms 4392 KB Output is correct
4 Correct 760 ms 4392 KB Output is correct
5 Correct 785 ms 4388 KB Output is correct
6 Correct 798 ms 4308 KB Output is correct
7 Correct 806 ms 4392 KB Output is correct
8 Correct 805 ms 4308 KB Output is correct
9 Correct 817 ms 4396 KB Output is correct
10 Correct 856 ms 4392 KB Output is correct
11 Correct 785 ms 4392 KB Output is correct
12 Correct 812 ms 4388 KB Output is correct
13 Correct 833 ms 4392 KB Output is correct
14 Correct 827 ms 4388 KB Output is correct
15 Correct 792 ms 4392 KB Output is correct
16 Correct 875 ms 4392 KB Output is correct
17 Correct 1053 ms 4388 KB Output is correct
18 Correct 835 ms 4388 KB Output is correct
19 Correct 842 ms 4388 KB Output is correct
20 Correct 843 ms 4388 KB Output is correct
21 Correct 1502 ms 4400 KB Output is correct
22 Correct 1338 ms 4388 KB Output is correct
23 Correct 1327 ms 4388 KB Output is correct
24 Correct 1405 ms 4388 KB Output is correct
25 Correct 1370 ms 4392 KB Output is correct
26 Correct 1723 ms 4392 KB Output is correct
27 Correct 1672 ms 4388 KB Output is correct
28 Correct 1654 ms 4384 KB Output is correct
29 Correct 1688 ms 4384 KB Output is correct
30 Correct 874 ms 4388 KB Output is correct
31 Correct 799 ms 4388 KB Output is correct
32 Correct 757 ms 4388 KB Output is correct
33 Correct 775 ms 4392 KB Output is correct
34 Correct 820 ms 4388 KB Output is correct
35 Correct 832 ms 4388 KB Output is correct
36 Correct 756 ms 4392 KB Output is correct
37 Correct 795 ms 4396 KB Output is correct
38 Correct 799 ms 4396 KB Output is correct
39 Correct 11 ms 1108 KB Output is correct
40 Correct 10 ms 1080 KB Output is correct
41 Correct 11 ms 1108 KB Output is correct
42 Correct 12 ms 1108 KB Output is correct
43 Correct 15 ms 1108 KB Output is correct
44 Correct 13 ms 1156 KB Output is correct
45 Correct 14 ms 1148 KB Output is correct
46 Correct 14 ms 1152 KB Output is correct
47 Correct 13 ms 1152 KB Output is correct
48 Correct 13 ms 1108 KB Output is correct
49 Correct 11 ms 1108 KB Output is correct
50 Correct 12 ms 1148 KB Output is correct
51 Correct 11 ms 1108 KB Output is correct
52 Correct 10 ms 1108 KB Output is correct
53 Correct 12 ms 1108 KB Output is correct
54 Correct 12 ms 1152 KB Output is correct
55 Correct 11 ms 1108 KB Output is correct
56 Correct 11 ms 1152 KB Output is correct
57 Correct 11 ms 1108 KB Output is correct
58 Correct 13 ms 1084 KB Output is correct
59 Correct 1292 ms 4392 KB Output is correct
60 Correct 1234 ms 4392 KB Output is correct
61 Correct 1204 ms 4388 KB Output is correct
62 Correct 1265 ms 4392 KB Output is correct
63 Correct 1231 ms 4392 KB Output is correct
64 Correct 1476 ms 4396 KB Output is correct
65 Correct 1479 ms 4396 KB Output is correct
66 Correct 1492 ms 4396 KB Output is correct
67 Correct 1461 ms 4392 KB Output is correct
68 Correct 1489 ms 4392 KB Output is correct
69 Correct 1183 ms 4400 KB Output is correct
70 Correct 1170 ms 4396 KB Output is correct
71 Correct 1186 ms 4392 KB Output is correct
72 Correct 1197 ms 4392 KB Output is correct
73 Correct 1208 ms 4388 KB Output is correct
74 Correct 1236 ms 4392 KB Output is correct
75 Correct 1253 ms 4392 KB Output is correct
76 Correct 1249 ms 4392 KB Output is correct
77 Correct 1255 ms 4392 KB Output is correct
78 Correct 1364 ms 4392 KB Output is correct