답안 #161083

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161083 2019-10-31T13:36:48 Z pzdba Boat (APIO16_boat) C++14
58 / 100
2000 ms 10448 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=0;j<=n;j++){
            D[i][j] = ncr(v[i]-v[i-1], j);
        }
    }
    for(int i=1;i<v.size();i++){
        for(int j=1;j<=n;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=l[i];j<=r[i];j++){
            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;
            }
        }

        for(int j=1;j<v.size();j++){
            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:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<v.size();i++){
                 ~^~~~~~~~~
boat.cpp:56:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<v.size();i++){
                 ~^~~~~~~~~
boat.cpp:74: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 1172 ms 10200 KB Output is correct
2 Correct 1171 ms 10228 KB Output is correct
3 Correct 1183 ms 10172 KB Output is correct
4 Correct 1190 ms 10344 KB Output is correct
5 Correct 1177 ms 10300 KB Output is correct
6 Correct 1183 ms 10448 KB Output is correct
7 Correct 1169 ms 10232 KB Output is correct
8 Correct 1175 ms 10296 KB Output is correct
9 Correct 1220 ms 10220 KB Output is correct
10 Correct 1312 ms 10260 KB Output is correct
11 Correct 1194 ms 10360 KB Output is correct
12 Correct 1185 ms 10268 KB Output is correct
13 Correct 1177 ms 10164 KB Output is correct
14 Correct 1170 ms 10160 KB Output is correct
15 Correct 1174 ms 10268 KB Output is correct
16 Correct 216 ms 6904 KB Output is correct
17 Correct 231 ms 7060 KB Output is correct
18 Correct 225 ms 6904 KB Output is correct
19 Correct 230 ms 7020 KB Output is correct
20 Correct 222 ms 6928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1172 ms 10200 KB Output is correct
2 Correct 1171 ms 10228 KB Output is correct
3 Correct 1183 ms 10172 KB Output is correct
4 Correct 1190 ms 10344 KB Output is correct
5 Correct 1177 ms 10300 KB Output is correct
6 Correct 1183 ms 10448 KB Output is correct
7 Correct 1169 ms 10232 KB Output is correct
8 Correct 1175 ms 10296 KB Output is correct
9 Correct 1220 ms 10220 KB Output is correct
10 Correct 1312 ms 10260 KB Output is correct
11 Correct 1194 ms 10360 KB Output is correct
12 Correct 1185 ms 10268 KB Output is correct
13 Correct 1177 ms 10164 KB Output is correct
14 Correct 1170 ms 10160 KB Output is correct
15 Correct 1174 ms 10268 KB Output is correct
16 Correct 216 ms 6904 KB Output is correct
17 Correct 231 ms 7060 KB Output is correct
18 Correct 225 ms 6904 KB Output is correct
19 Correct 230 ms 7020 KB Output is correct
20 Correct 222 ms 6928 KB Output is correct
21 Correct 947 ms 9996 KB Output is correct
22 Correct 956 ms 9912 KB Output is correct
23 Correct 938 ms 9948 KB Output is correct
24 Correct 961 ms 9808 KB Output is correct
25 Correct 940 ms 9976 KB Output is correct
26 Correct 1012 ms 9804 KB Output is correct
27 Correct 1046 ms 9696 KB Output is correct
28 Correct 1000 ms 9720 KB Output is correct
29 Correct 1090 ms 9864 KB Output is correct
30 Correct 1119 ms 10360 KB Output is correct
31 Correct 1115 ms 10244 KB Output is correct
32 Correct 1120 ms 10256 KB Output is correct
33 Correct 1131 ms 10264 KB Output is correct
34 Correct 1108 ms 10176 KB Output is correct
35 Correct 1124 ms 10220 KB Output is correct
36 Correct 1097 ms 10360 KB Output is correct
37 Correct 1130 ms 10248 KB Output is correct
38 Correct 1102 ms 10416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5496 KB Output is correct
2 Correct 23 ms 5496 KB Output is correct
3 Correct 22 ms 5496 KB Output is correct
4 Correct 22 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 24 ms 5496 KB Output is correct
8 Correct 23 ms 5496 KB Output is correct
9 Correct 23 ms 5456 KB Output is correct
10 Correct 23 ms 5500 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 5496 KB Output is correct
14 Correct 22 ms 5496 KB Output is correct
15 Correct 22 ms 5496 KB Output is correct
16 Correct 16 ms 5112 KB Output is correct
17 Correct 15 ms 5112 KB Output is correct
18 Correct 17 ms 5112 KB Output is correct
19 Correct 16 ms 5112 KB Output is correct
20 Correct 15 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1172 ms 10200 KB Output is correct
2 Correct 1171 ms 10228 KB Output is correct
3 Correct 1183 ms 10172 KB Output is correct
4 Correct 1190 ms 10344 KB Output is correct
5 Correct 1177 ms 10300 KB Output is correct
6 Correct 1183 ms 10448 KB Output is correct
7 Correct 1169 ms 10232 KB Output is correct
8 Correct 1175 ms 10296 KB Output is correct
9 Correct 1220 ms 10220 KB Output is correct
10 Correct 1312 ms 10260 KB Output is correct
11 Correct 1194 ms 10360 KB Output is correct
12 Correct 1185 ms 10268 KB Output is correct
13 Correct 1177 ms 10164 KB Output is correct
14 Correct 1170 ms 10160 KB Output is correct
15 Correct 1174 ms 10268 KB Output is correct
16 Correct 216 ms 6904 KB Output is correct
17 Correct 231 ms 7060 KB Output is correct
18 Correct 225 ms 6904 KB Output is correct
19 Correct 230 ms 7020 KB Output is correct
20 Correct 222 ms 6928 KB Output is correct
21 Correct 947 ms 9996 KB Output is correct
22 Correct 956 ms 9912 KB Output is correct
23 Correct 938 ms 9948 KB Output is correct
24 Correct 961 ms 9808 KB Output is correct
25 Correct 940 ms 9976 KB Output is correct
26 Correct 1012 ms 9804 KB Output is correct
27 Correct 1046 ms 9696 KB Output is correct
28 Correct 1000 ms 9720 KB Output is correct
29 Correct 1090 ms 9864 KB Output is correct
30 Correct 1119 ms 10360 KB Output is correct
31 Correct 1115 ms 10244 KB Output is correct
32 Correct 1120 ms 10256 KB Output is correct
33 Correct 1131 ms 10264 KB Output is correct
34 Correct 1108 ms 10176 KB Output is correct
35 Correct 1124 ms 10220 KB Output is correct
36 Correct 1097 ms 10360 KB Output is correct
37 Correct 1130 ms 10248 KB Output is correct
38 Correct 1102 ms 10416 KB Output is correct
39 Correct 22 ms 5496 KB Output is correct
40 Correct 23 ms 5496 KB Output is correct
41 Correct 22 ms 5496 KB Output is correct
42 Correct 22 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 24 ms 5496 KB Output is correct
46 Correct 23 ms 5496 KB Output is correct
47 Correct 23 ms 5456 KB Output is correct
48 Correct 23 ms 5500 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 5496 KB Output is correct
52 Correct 22 ms 5496 KB Output is correct
53 Correct 22 ms 5496 KB Output is correct
54 Correct 16 ms 5112 KB Output is correct
55 Correct 15 ms 5112 KB Output is correct
56 Correct 17 ms 5112 KB Output is correct
57 Correct 16 ms 5112 KB Output is correct
58 Correct 15 ms 5112 KB Output is correct
59 Correct 1950 ms 10232 KB Output is correct
60 Correct 1899 ms 10372 KB Output is correct
61 Correct 1851 ms 10188 KB Output is correct
62 Execution timed out 2049 ms 9996 KB Time limit exceeded
63 Halted 0 ms 0 KB -