Submission #624380

# Submission time Handle Problem Language Result Execution time Memory
624380 2022-08-08T05:35:29 Z socpite Boat (APIO16_boat) C++14
58 / 100
2000 ms 13948 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

typedef long long ll;

const int maxn = 1005;
const int mod = 1e9+7;

int n;

pair<int, int> A[maxn];
vector<int> cp;

ll dp[maxn][2*maxn], pc[2*maxn][maxn], inv[maxn];


int main(){
    inv[0] = inv[1] = 1;
    for(int i = 2; i < maxn; i++)inv[i]=mod - inv[mod%i]*(mod/i)%mod;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> A[i].f >> A[i].s;
        cp.push_back(A[i].f-1);
        cp.push_back(A[i].s);
    }
    cp.push_back(0);
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    for(int i = 1; i < cp.size(); i++){
        ll len = cp[i]-cp[i-1];
        pc[i][1] = len;
        for(int j = 2; j <= n; j++){
            ll crr = len*(len-1)/2;
            crr%=mod;
            for(int k = 2; k <= min({n, int(len), j}); k++){
                pc[i][j] += crr;
                // C(k-2, j-2)*C(k, len)
                if(pc[i][j] >= mod)pc[i][j]-=mod;
                k-=2;
                crr=crr*(j-k-2)%mod;
                crr=crr*inv[k+1]%mod;
                k+=2;
                crr=crr*(len-k)%mod;
                crr=crr*inv[k+1]%mod;
            }
        }
    }
    for(int i = 0; i < cp.size(); i++)dp[0][i]=1;
    for(int i = 0; i <= n; i++)dp[i][0]=1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j < cp.size(); j++){
            if(A[i].f > cp[j] || A[i].s <= cp[j-1])dp[i][j]=0;
            else{
                int cnt = 0;
                for(int k = i; k > 0; k--){
                    if(A[k].s >= cp[j] && A[k].f <= cp[j-1]+1){
                        cnt++;
                        dp[i][j]+=dp[k-1][j-1]*pc[j][cnt]%mod;
                        dp[i][j]%=mod;
                    }
                }
            }
            //cout << i << " " << j << " " << dp[i][j] << endl;
            dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
            dp[i][j]%=mod;
        }
    }
    ll ans = dp[n][cp.size()-1]-1;
    ans%=mod;
    if(ans < 0)ans+=mod;
    cout << ans;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = 1; i < cp.size(); i++){
      |                    ~~^~~~~~~~~~~
boat.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 0; i < cp.size(); i++)dp[0][i]=1;
      |                    ~~^~~~~~~~~~~
boat.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(int j = 1; j < cp.size(); j++){
      |                        ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1217 ms 12220 KB Output is correct
2 Correct 1173 ms 12300 KB Output is correct
3 Correct 1180 ms 12272 KB Output is correct
4 Correct 1162 ms 12204 KB Output is correct
5 Correct 1157 ms 12176 KB Output is correct
6 Correct 1168 ms 12124 KB Output is correct
7 Correct 1177 ms 12264 KB Output is correct
8 Correct 1165 ms 12172 KB Output is correct
9 Correct 1173 ms 12168 KB Output is correct
10 Correct 1157 ms 12132 KB Output is correct
11 Correct 1175 ms 12272 KB Output is correct
12 Correct 1162 ms 12244 KB Output is correct
13 Correct 1161 ms 12136 KB Output is correct
14 Correct 1173 ms 12228 KB Output is correct
15 Correct 1186 ms 12188 KB Output is correct
16 Correct 204 ms 4072 KB Output is correct
17 Correct 232 ms 4212 KB Output is correct
18 Correct 218 ms 4120 KB Output is correct
19 Correct 218 ms 4148 KB Output is correct
20 Correct 239 ms 4148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1217 ms 12220 KB Output is correct
2 Correct 1173 ms 12300 KB Output is correct
3 Correct 1180 ms 12272 KB Output is correct
4 Correct 1162 ms 12204 KB Output is correct
5 Correct 1157 ms 12176 KB Output is correct
6 Correct 1168 ms 12124 KB Output is correct
7 Correct 1177 ms 12264 KB Output is correct
8 Correct 1165 ms 12172 KB Output is correct
9 Correct 1173 ms 12168 KB Output is correct
10 Correct 1157 ms 12132 KB Output is correct
11 Correct 1175 ms 12272 KB Output is correct
12 Correct 1162 ms 12244 KB Output is correct
13 Correct 1161 ms 12136 KB Output is correct
14 Correct 1173 ms 12228 KB Output is correct
15 Correct 1186 ms 12188 KB Output is correct
16 Correct 204 ms 4072 KB Output is correct
17 Correct 232 ms 4212 KB Output is correct
18 Correct 218 ms 4120 KB Output is correct
19 Correct 218 ms 4148 KB Output is correct
20 Correct 239 ms 4148 KB Output is correct
21 Correct 158 ms 12460 KB Output is correct
22 Correct 151 ms 12472 KB Output is correct
23 Correct 150 ms 12308 KB Output is correct
24 Correct 206 ms 12356 KB Output is correct
25 Correct 157 ms 12368 KB Output is correct
26 Correct 226 ms 11944 KB Output is correct
27 Correct 235 ms 12008 KB Output is correct
28 Correct 230 ms 12000 KB Output is correct
29 Correct 217 ms 12024 KB Output is correct
30 Correct 1111 ms 13828 KB Output is correct
31 Correct 1108 ms 13860 KB Output is correct
32 Correct 1115 ms 13856 KB Output is correct
33 Correct 1115 ms 13948 KB Output is correct
34 Correct 1117 ms 13848 KB Output is correct
35 Correct 1093 ms 12196 KB Output is correct
36 Correct 1108 ms 12136 KB Output is correct
37 Correct 1113 ms 12112 KB Output is correct
38 Correct 1113 ms 12168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1748 KB Output is correct
2 Correct 20 ms 1748 KB Output is correct
3 Correct 20 ms 1848 KB Output is correct
4 Correct 21 ms 1796 KB Output is correct
5 Correct 20 ms 1844 KB Output is correct
6 Correct 22 ms 1852 KB Output is correct
7 Correct 25 ms 1748 KB Output is correct
8 Correct 23 ms 1824 KB Output is correct
9 Correct 22 ms 1852 KB Output is correct
10 Correct 21 ms 1728 KB Output is correct
11 Correct 20 ms 1748 KB Output is correct
12 Correct 20 ms 1860 KB Output is correct
13 Correct 20 ms 1816 KB Output is correct
14 Correct 20 ms 1748 KB Output is correct
15 Correct 21 ms 1836 KB Output is correct
16 Correct 10 ms 1364 KB Output is correct
17 Correct 9 ms 1244 KB Output is correct
18 Correct 9 ms 1268 KB Output is correct
19 Correct 10 ms 1236 KB Output is correct
20 Correct 10 ms 1292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1217 ms 12220 KB Output is correct
2 Correct 1173 ms 12300 KB Output is correct
3 Correct 1180 ms 12272 KB Output is correct
4 Correct 1162 ms 12204 KB Output is correct
5 Correct 1157 ms 12176 KB Output is correct
6 Correct 1168 ms 12124 KB Output is correct
7 Correct 1177 ms 12264 KB Output is correct
8 Correct 1165 ms 12172 KB Output is correct
9 Correct 1173 ms 12168 KB Output is correct
10 Correct 1157 ms 12132 KB Output is correct
11 Correct 1175 ms 12272 KB Output is correct
12 Correct 1162 ms 12244 KB Output is correct
13 Correct 1161 ms 12136 KB Output is correct
14 Correct 1173 ms 12228 KB Output is correct
15 Correct 1186 ms 12188 KB Output is correct
16 Correct 204 ms 4072 KB Output is correct
17 Correct 232 ms 4212 KB Output is correct
18 Correct 218 ms 4120 KB Output is correct
19 Correct 218 ms 4148 KB Output is correct
20 Correct 239 ms 4148 KB Output is correct
21 Correct 158 ms 12460 KB Output is correct
22 Correct 151 ms 12472 KB Output is correct
23 Correct 150 ms 12308 KB Output is correct
24 Correct 206 ms 12356 KB Output is correct
25 Correct 157 ms 12368 KB Output is correct
26 Correct 226 ms 11944 KB Output is correct
27 Correct 235 ms 12008 KB Output is correct
28 Correct 230 ms 12000 KB Output is correct
29 Correct 217 ms 12024 KB Output is correct
30 Correct 1111 ms 13828 KB Output is correct
31 Correct 1108 ms 13860 KB Output is correct
32 Correct 1115 ms 13856 KB Output is correct
33 Correct 1115 ms 13948 KB Output is correct
34 Correct 1117 ms 13848 KB Output is correct
35 Correct 1093 ms 12196 KB Output is correct
36 Correct 1108 ms 12136 KB Output is correct
37 Correct 1113 ms 12112 KB Output is correct
38 Correct 1113 ms 12168 KB Output is correct
39 Correct 20 ms 1748 KB Output is correct
40 Correct 20 ms 1748 KB Output is correct
41 Correct 20 ms 1848 KB Output is correct
42 Correct 21 ms 1796 KB Output is correct
43 Correct 20 ms 1844 KB Output is correct
44 Correct 22 ms 1852 KB Output is correct
45 Correct 25 ms 1748 KB Output is correct
46 Correct 23 ms 1824 KB Output is correct
47 Correct 22 ms 1852 KB Output is correct
48 Correct 21 ms 1728 KB Output is correct
49 Correct 20 ms 1748 KB Output is correct
50 Correct 20 ms 1860 KB Output is correct
51 Correct 20 ms 1816 KB Output is correct
52 Correct 20 ms 1748 KB Output is correct
53 Correct 21 ms 1836 KB Output is correct
54 Correct 10 ms 1364 KB Output is correct
55 Correct 9 ms 1244 KB Output is correct
56 Correct 9 ms 1268 KB Output is correct
57 Correct 10 ms 1236 KB Output is correct
58 Correct 10 ms 1292 KB Output is correct
59 Execution timed out 2069 ms 7392 KB Time limit exceeded
60 Halted 0 ms 0 KB -