Submission #161097

# Submission time Handle Problem Language Result Execution time Memory
161097 2019-10-31T13:59:01 Z pzdba Boat (APIO16_boat) C++14
58 / 100
2000 ms 10380 KB
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int binPow(int a, int b){
    int ans = 1;
    while(b){
        if(b%2 == 1) ans = ans*1ll*a%mod;
        a = a*1ll*a%mod;
        b/=2;
    }
    return ans;
}
int f[1001], inv[1001], a[501], b[501], l[501], r[501];
int ncr(int a, int b){
    if(b > a) return 0;
    int mn = min(a-b, b), mx = max(a-b, b);
    int ans = 1;
    for(int i=a;i>mx;i--) ans = (ans*1ll*i)%mod;
    return ans*1ll*inv[mn]%mod;
}

int dp[501][1001];
int D[1001][501], C[1001][1001];
int sum[1001][501];
int main(){
    C[0][0] = 1;
    for(int i=1;i<=1000;i++){
        C[i][0] = C[i][i] = 1;
        for(int j=1;j<i;j++){
            C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
        }
    }
    f[0] = 1;
    for(int i=1;i<=1000;i++) f[i] = f[i-1]*1ll*i%mod;
    for(int i=0;i<=1000;i++) inv[i] = binPow(f[i], mod-2);
    int n;
    scanf("%d", &n);

    vector<int> v;
    for(int i=1;i<=n;i++){
        scanf("%d%d", &a[i], &b[i]);
        v.push_back(a[i]-1);
        v.push_back(b[i]);
    }   
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for(int i=1;i<=n;i++){
        l[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
        r[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
    }
     for(int i=1;i<v.size();i++){
         for(int j=1;j<=n;j++){
             D[i][j] = ncr(v[i]-v[i-1], j);
             for(int l=0;l<j;l++){
                 sum[i][j] = (sum[i][j] + D[i][l+1]*1ll*C[j-1][l])%mod;
             }
         }
     }
    for(int j=0;j<=1000;j++) dp[0][j] = 1;
    int ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<v.size();j++){
            if(l[i] <= j && j <= r[i]){
                int cnt = 0;
                for(int k=i;k>=1;k--){
                    if(l[k] <= j && j <= r[k]) cnt++;
                    dp[i][j] = (dp[i][j] + dp[k-1][j-1]*1ll*sum[j][cnt])%mod;
                }
            }
            dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
        }
        ans = (ans + dp[i][v.size()-1])%mod;
    }
    printf("%d\n", ans);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for(int i=1;i<v.size();i++){
                  ~^~~~~~~~~
boat.cpp:62:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=1;j<v.size();j++){
                     ~^~~~~~~~~
boat.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a[i], &b[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1169 ms 10284 KB Output is correct
2 Correct 1176 ms 10136 KB Output is correct
3 Correct 1182 ms 10332 KB Output is correct
4 Correct 1165 ms 10260 KB Output is correct
5 Correct 1174 ms 10196 KB Output is correct
6 Correct 1179 ms 10380 KB Output is correct
7 Correct 1180 ms 10108 KB Output is correct
8 Correct 1197 ms 10204 KB Output is correct
9 Correct 1190 ms 10224 KB Output is correct
10 Correct 1200 ms 10276 KB Output is correct
11 Correct 1217 ms 10316 KB Output is correct
12 Correct 1191 ms 10132 KB Output is correct
13 Correct 1181 ms 10280 KB Output is correct
14 Correct 1167 ms 10104 KB Output is correct
15 Correct 1170 ms 10232 KB Output is correct
16 Correct 215 ms 6876 KB Output is correct
17 Correct 231 ms 6904 KB Output is correct
18 Correct 282 ms 7048 KB Output is correct
19 Correct 233 ms 7032 KB Output is correct
20 Correct 224 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1169 ms 10284 KB Output is correct
2 Correct 1176 ms 10136 KB Output is correct
3 Correct 1182 ms 10332 KB Output is correct
4 Correct 1165 ms 10260 KB Output is correct
5 Correct 1174 ms 10196 KB Output is correct
6 Correct 1179 ms 10380 KB Output is correct
7 Correct 1180 ms 10108 KB Output is correct
8 Correct 1197 ms 10204 KB Output is correct
9 Correct 1190 ms 10224 KB Output is correct
10 Correct 1200 ms 10276 KB Output is correct
11 Correct 1217 ms 10316 KB Output is correct
12 Correct 1191 ms 10132 KB Output is correct
13 Correct 1181 ms 10280 KB Output is correct
14 Correct 1167 ms 10104 KB Output is correct
15 Correct 1170 ms 10232 KB Output is correct
16 Correct 215 ms 6876 KB Output is correct
17 Correct 231 ms 6904 KB Output is correct
18 Correct 282 ms 7048 KB Output is correct
19 Correct 233 ms 7032 KB Output is correct
20 Correct 224 ms 6904 KB Output is correct
21 Correct 955 ms 9892 KB Output is correct
22 Correct 955 ms 9972 KB Output is correct
23 Correct 919 ms 9844 KB Output is correct
24 Correct 928 ms 9716 KB Output is correct
25 Correct 958 ms 9856 KB Output is correct
26 Correct 1034 ms 9812 KB Output is correct
27 Correct 1052 ms 9756 KB Output is correct
28 Correct 1002 ms 9780 KB Output is correct
29 Correct 1026 ms 9808 KB Output is correct
30 Correct 1146 ms 10260 KB Output is correct
31 Correct 1106 ms 10240 KB Output is correct
32 Correct 1128 ms 10180 KB Output is correct
33 Correct 1093 ms 10136 KB Output is correct
34 Correct 1104 ms 10220 KB Output is correct
35 Correct 1091 ms 10168 KB Output is correct
36 Correct 1111 ms 10336 KB Output is correct
37 Correct 1123 ms 10328 KB Output is correct
38 Correct 1102 ms 10308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 5496 KB Output is correct
2 Correct 22 ms 5496 KB Output is correct
3 Correct 24 ms 5496 KB Output is correct
4 Correct 22 ms 5496 KB Output is correct
5 Correct 23 ms 5572 KB Output is correct
6 Correct 23 ms 5496 KB Output is correct
7 Correct 23 ms 5496 KB Output is correct
8 Correct 23 ms 5368 KB Output is correct
9 Correct 23 ms 5368 KB Output is correct
10 Correct 23 ms 5496 KB Output is correct
11 Correct 22 ms 5496 KB Output is correct
12 Correct 22 ms 5496 KB Output is correct
13 Correct 23 ms 5496 KB Output is correct
14 Correct 22 ms 5496 KB Output is correct
15 Correct 24 ms 5372 KB Output is correct
16 Correct 15 ms 5112 KB Output is correct
17 Correct 16 ms 5112 KB Output is correct
18 Correct 15 ms 5112 KB Output is correct
19 Correct 20 ms 5112 KB Output is correct
20 Correct 16 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1169 ms 10284 KB Output is correct
2 Correct 1176 ms 10136 KB Output is correct
3 Correct 1182 ms 10332 KB Output is correct
4 Correct 1165 ms 10260 KB Output is correct
5 Correct 1174 ms 10196 KB Output is correct
6 Correct 1179 ms 10380 KB Output is correct
7 Correct 1180 ms 10108 KB Output is correct
8 Correct 1197 ms 10204 KB Output is correct
9 Correct 1190 ms 10224 KB Output is correct
10 Correct 1200 ms 10276 KB Output is correct
11 Correct 1217 ms 10316 KB Output is correct
12 Correct 1191 ms 10132 KB Output is correct
13 Correct 1181 ms 10280 KB Output is correct
14 Correct 1167 ms 10104 KB Output is correct
15 Correct 1170 ms 10232 KB Output is correct
16 Correct 215 ms 6876 KB Output is correct
17 Correct 231 ms 6904 KB Output is correct
18 Correct 282 ms 7048 KB Output is correct
19 Correct 233 ms 7032 KB Output is correct
20 Correct 224 ms 6904 KB Output is correct
21 Correct 955 ms 9892 KB Output is correct
22 Correct 955 ms 9972 KB Output is correct
23 Correct 919 ms 9844 KB Output is correct
24 Correct 928 ms 9716 KB Output is correct
25 Correct 958 ms 9856 KB Output is correct
26 Correct 1034 ms 9812 KB Output is correct
27 Correct 1052 ms 9756 KB Output is correct
28 Correct 1002 ms 9780 KB Output is correct
29 Correct 1026 ms 9808 KB Output is correct
30 Correct 1146 ms 10260 KB Output is correct
31 Correct 1106 ms 10240 KB Output is correct
32 Correct 1128 ms 10180 KB Output is correct
33 Correct 1093 ms 10136 KB Output is correct
34 Correct 1104 ms 10220 KB Output is correct
35 Correct 1091 ms 10168 KB Output is correct
36 Correct 1111 ms 10336 KB Output is correct
37 Correct 1123 ms 10328 KB Output is correct
38 Correct 1102 ms 10308 KB Output is correct
39 Correct 22 ms 5496 KB Output is correct
40 Correct 22 ms 5496 KB Output is correct
41 Correct 24 ms 5496 KB Output is correct
42 Correct 22 ms 5496 KB Output is correct
43 Correct 23 ms 5572 KB Output is correct
44 Correct 23 ms 5496 KB Output is correct
45 Correct 23 ms 5496 KB Output is correct
46 Correct 23 ms 5368 KB Output is correct
47 Correct 23 ms 5368 KB Output is correct
48 Correct 23 ms 5496 KB Output is correct
49 Correct 22 ms 5496 KB Output is correct
50 Correct 22 ms 5496 KB Output is correct
51 Correct 23 ms 5496 KB Output is correct
52 Correct 22 ms 5496 KB Output is correct
53 Correct 24 ms 5372 KB Output is correct
54 Correct 15 ms 5112 KB Output is correct
55 Correct 16 ms 5112 KB Output is correct
56 Correct 15 ms 5112 KB Output is correct
57 Correct 20 ms 5112 KB Output is correct
58 Correct 16 ms 5112 KB Output is correct
59 Correct 1893 ms 10256 KB Output is correct
60 Execution timed out 2009 ms 10236 KB Time limit exceeded
61 Halted 0 ms 0 KB -