답안 #161099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161099 2019-10-31T14:06:16 Z pzdba Boat (APIO16_boat) C++14
58 / 100
2000 ms 10396 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++){
            D[j][i] = ncr(v[j]-v[j-1], i);
            for(int l=0;l<i;l++){
                sum[j][i] = (sum[j][i] + D[j][l+1]*1ll*C[i-1][l])%mod;
            }

            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: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]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1198 ms 10252 KB Output is correct
2 Correct 1278 ms 10260 KB Output is correct
3 Correct 1241 ms 10260 KB Output is correct
4 Correct 1203 ms 10232 KB Output is correct
5 Correct 1224 ms 10196 KB Output is correct
6 Correct 1267 ms 10176 KB Output is correct
7 Correct 1226 ms 10284 KB Output is correct
8 Correct 1192 ms 10268 KB Output is correct
9 Correct 1219 ms 10396 KB Output is correct
10 Correct 1216 ms 10208 KB Output is correct
11 Correct 1200 ms 10116 KB Output is correct
12 Correct 1211 ms 10232 KB Output is correct
13 Correct 1211 ms 10272 KB Output is correct
14 Correct 1195 ms 10132 KB Output is correct
15 Correct 1184 ms 10264 KB Output is correct
16 Correct 215 ms 6972 KB Output is correct
17 Correct 229 ms 6988 KB Output is correct
18 Correct 232 ms 6908 KB Output is correct
19 Correct 229 ms 7060 KB Output is correct
20 Correct 222 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1198 ms 10252 KB Output is correct
2 Correct 1278 ms 10260 KB Output is correct
3 Correct 1241 ms 10260 KB Output is correct
4 Correct 1203 ms 10232 KB Output is correct
5 Correct 1224 ms 10196 KB Output is correct
6 Correct 1267 ms 10176 KB Output is correct
7 Correct 1226 ms 10284 KB Output is correct
8 Correct 1192 ms 10268 KB Output is correct
9 Correct 1219 ms 10396 KB Output is correct
10 Correct 1216 ms 10208 KB Output is correct
11 Correct 1200 ms 10116 KB Output is correct
12 Correct 1211 ms 10232 KB Output is correct
13 Correct 1211 ms 10272 KB Output is correct
14 Correct 1195 ms 10132 KB Output is correct
15 Correct 1184 ms 10264 KB Output is correct
16 Correct 215 ms 6972 KB Output is correct
17 Correct 229 ms 6988 KB Output is correct
18 Correct 232 ms 6908 KB Output is correct
19 Correct 229 ms 7060 KB Output is correct
20 Correct 222 ms 6904 KB Output is correct
21 Correct 1052 ms 9832 KB Output is correct
22 Correct 1051 ms 10152 KB Output is correct
23 Correct 1014 ms 10008 KB Output is correct
24 Correct 1065 ms 9884 KB Output is correct
25 Correct 998 ms 9860 KB Output is correct
26 Correct 1049 ms 9880 KB Output is correct
27 Correct 1081 ms 9976 KB Output is correct
28 Correct 1069 ms 9672 KB Output is correct
29 Correct 1037 ms 9776 KB Output is correct
30 Correct 1133 ms 10260 KB Output is correct
31 Correct 1122 ms 10100 KB Output is correct
32 Correct 1139 ms 10332 KB Output is correct
33 Correct 1282 ms 10236 KB Output is correct
34 Correct 1132 ms 10212 KB Output is correct
35 Correct 1141 ms 10164 KB Output is correct
36 Correct 1111 ms 10348 KB Output is correct
37 Correct 1129 ms 10232 KB Output is correct
38 Correct 1155 ms 10088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5368 KB Output is correct
2 Correct 23 ms 5496 KB Output is correct
3 Correct 22 ms 5496 KB Output is correct
4 Correct 23 ms 5496 KB Output is correct
5 Correct 23 ms 5496 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 5496 KB Output is correct
9 Correct 23 ms 5496 KB Output is correct
10 Correct 23 ms 5496 KB Output is correct
11 Correct 23 ms 5496 KB Output is correct
12 Correct 22 ms 5496 KB Output is correct
13 Correct 22 ms 5368 KB Output is correct
14 Correct 22 ms 5496 KB Output is correct
15 Correct 22 ms 5368 KB Output is correct
16 Correct 23 ms 5112 KB Output is correct
17 Correct 15 ms 5084 KB Output is correct
18 Correct 14 ms 5112 KB Output is correct
19 Correct 15 ms 5112 KB Output is correct
20 Correct 15 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1198 ms 10252 KB Output is correct
2 Correct 1278 ms 10260 KB Output is correct
3 Correct 1241 ms 10260 KB Output is correct
4 Correct 1203 ms 10232 KB Output is correct
5 Correct 1224 ms 10196 KB Output is correct
6 Correct 1267 ms 10176 KB Output is correct
7 Correct 1226 ms 10284 KB Output is correct
8 Correct 1192 ms 10268 KB Output is correct
9 Correct 1219 ms 10396 KB Output is correct
10 Correct 1216 ms 10208 KB Output is correct
11 Correct 1200 ms 10116 KB Output is correct
12 Correct 1211 ms 10232 KB Output is correct
13 Correct 1211 ms 10272 KB Output is correct
14 Correct 1195 ms 10132 KB Output is correct
15 Correct 1184 ms 10264 KB Output is correct
16 Correct 215 ms 6972 KB Output is correct
17 Correct 229 ms 6988 KB Output is correct
18 Correct 232 ms 6908 KB Output is correct
19 Correct 229 ms 7060 KB Output is correct
20 Correct 222 ms 6904 KB Output is correct
21 Correct 1052 ms 9832 KB Output is correct
22 Correct 1051 ms 10152 KB Output is correct
23 Correct 1014 ms 10008 KB Output is correct
24 Correct 1065 ms 9884 KB Output is correct
25 Correct 998 ms 9860 KB Output is correct
26 Correct 1049 ms 9880 KB Output is correct
27 Correct 1081 ms 9976 KB Output is correct
28 Correct 1069 ms 9672 KB Output is correct
29 Correct 1037 ms 9776 KB Output is correct
30 Correct 1133 ms 10260 KB Output is correct
31 Correct 1122 ms 10100 KB Output is correct
32 Correct 1139 ms 10332 KB Output is correct
33 Correct 1282 ms 10236 KB Output is correct
34 Correct 1132 ms 10212 KB Output is correct
35 Correct 1141 ms 10164 KB Output is correct
36 Correct 1111 ms 10348 KB Output is correct
37 Correct 1129 ms 10232 KB Output is correct
38 Correct 1155 ms 10088 KB Output is correct
39 Correct 22 ms 5368 KB Output is correct
40 Correct 23 ms 5496 KB Output is correct
41 Correct 22 ms 5496 KB Output is correct
42 Correct 23 ms 5496 KB Output is correct
43 Correct 23 ms 5496 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 5496 KB Output is correct
47 Correct 23 ms 5496 KB Output is correct
48 Correct 23 ms 5496 KB Output is correct
49 Correct 23 ms 5496 KB Output is correct
50 Correct 22 ms 5496 KB Output is correct
51 Correct 22 ms 5368 KB Output is correct
52 Correct 22 ms 5496 KB Output is correct
53 Correct 22 ms 5368 KB Output is correct
54 Correct 23 ms 5112 KB Output is correct
55 Correct 15 ms 5084 KB Output is correct
56 Correct 14 ms 5112 KB Output is correct
57 Correct 15 ms 5112 KB Output is correct
58 Correct 15 ms 5112 KB Output is correct
59 Execution timed out 2044 ms 10188 KB Time limit exceeded
60 Halted 0 ms 0 KB -