답안 #161087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161087 2019-10-31T13:47:15 Z pzdba Boat (APIO16_boat) C++14
58 / 100
2000 ms 10400 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:18: 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]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1164 ms 10356 KB Output is correct
2 Correct 1168 ms 10076 KB Output is correct
3 Correct 1175 ms 10316 KB Output is correct
4 Correct 1203 ms 10260 KB Output is correct
5 Correct 1224 ms 10276 KB Output is correct
6 Correct 1217 ms 10304 KB Output is correct
7 Correct 1185 ms 10116 KB Output is correct
8 Correct 1199 ms 10336 KB Output is correct
9 Correct 1216 ms 10272 KB Output is correct
10 Correct 1196 ms 10304 KB Output is correct
11 Correct 1169 ms 10400 KB Output is correct
12 Correct 1194 ms 10336 KB Output is correct
13 Correct 1163 ms 10184 KB Output is correct
14 Correct 1170 ms 10204 KB Output is correct
15 Correct 1180 ms 10280 KB Output is correct
16 Correct 221 ms 7032 KB Output is correct
17 Correct 231 ms 7032 KB Output is correct
18 Correct 221 ms 7028 KB Output is correct
19 Correct 238 ms 7116 KB Output is correct
20 Correct 236 ms 7032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1164 ms 10356 KB Output is correct
2 Correct 1168 ms 10076 KB Output is correct
3 Correct 1175 ms 10316 KB Output is correct
4 Correct 1203 ms 10260 KB Output is correct
5 Correct 1224 ms 10276 KB Output is correct
6 Correct 1217 ms 10304 KB Output is correct
7 Correct 1185 ms 10116 KB Output is correct
8 Correct 1199 ms 10336 KB Output is correct
9 Correct 1216 ms 10272 KB Output is correct
10 Correct 1196 ms 10304 KB Output is correct
11 Correct 1169 ms 10400 KB Output is correct
12 Correct 1194 ms 10336 KB Output is correct
13 Correct 1163 ms 10184 KB Output is correct
14 Correct 1170 ms 10204 KB Output is correct
15 Correct 1180 ms 10280 KB Output is correct
16 Correct 221 ms 7032 KB Output is correct
17 Correct 231 ms 7032 KB Output is correct
18 Correct 221 ms 7028 KB Output is correct
19 Correct 238 ms 7116 KB Output is correct
20 Correct 236 ms 7032 KB Output is correct
21 Correct 942 ms 10040 KB Output is correct
22 Correct 979 ms 9920 KB Output is correct
23 Correct 924 ms 9960 KB Output is correct
24 Correct 951 ms 9872 KB Output is correct
25 Correct 947 ms 9992 KB Output is correct
26 Correct 1016 ms 9888 KB Output is correct
27 Correct 1049 ms 9848 KB Output is correct
28 Correct 1014 ms 9748 KB Output is correct
29 Correct 1010 ms 9848 KB Output is correct
30 Correct 1160 ms 10328 KB Output is correct
31 Correct 1122 ms 10332 KB Output is correct
32 Correct 1111 ms 10360 KB Output is correct
33 Correct 1119 ms 10144 KB Output is correct
34 Correct 1086 ms 10188 KB Output is correct
35 Correct 1083 ms 10288 KB Output is correct
36 Correct 1085 ms 10192 KB Output is correct
37 Correct 1122 ms 10292 KB Output is correct
38 Correct 1105 ms 10104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5496 KB Output is correct
2 Correct 22 ms 5368 KB Output is correct
3 Correct 23 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 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 5488 KB Output is correct
11 Correct 22 ms 5496 KB Output is correct
12 Correct 22 ms 5500 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 5468 KB Output is correct
16 Correct 15 ms 5112 KB Output is correct
17 Correct 15 ms 5116 KB Output is correct
18 Correct 15 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 1164 ms 10356 KB Output is correct
2 Correct 1168 ms 10076 KB Output is correct
3 Correct 1175 ms 10316 KB Output is correct
4 Correct 1203 ms 10260 KB Output is correct
5 Correct 1224 ms 10276 KB Output is correct
6 Correct 1217 ms 10304 KB Output is correct
7 Correct 1185 ms 10116 KB Output is correct
8 Correct 1199 ms 10336 KB Output is correct
9 Correct 1216 ms 10272 KB Output is correct
10 Correct 1196 ms 10304 KB Output is correct
11 Correct 1169 ms 10400 KB Output is correct
12 Correct 1194 ms 10336 KB Output is correct
13 Correct 1163 ms 10184 KB Output is correct
14 Correct 1170 ms 10204 KB Output is correct
15 Correct 1180 ms 10280 KB Output is correct
16 Correct 221 ms 7032 KB Output is correct
17 Correct 231 ms 7032 KB Output is correct
18 Correct 221 ms 7028 KB Output is correct
19 Correct 238 ms 7116 KB Output is correct
20 Correct 236 ms 7032 KB Output is correct
21 Correct 942 ms 10040 KB Output is correct
22 Correct 979 ms 9920 KB Output is correct
23 Correct 924 ms 9960 KB Output is correct
24 Correct 951 ms 9872 KB Output is correct
25 Correct 947 ms 9992 KB Output is correct
26 Correct 1016 ms 9888 KB Output is correct
27 Correct 1049 ms 9848 KB Output is correct
28 Correct 1014 ms 9748 KB Output is correct
29 Correct 1010 ms 9848 KB Output is correct
30 Correct 1160 ms 10328 KB Output is correct
31 Correct 1122 ms 10332 KB Output is correct
32 Correct 1111 ms 10360 KB Output is correct
33 Correct 1119 ms 10144 KB Output is correct
34 Correct 1086 ms 10188 KB Output is correct
35 Correct 1083 ms 10288 KB Output is correct
36 Correct 1085 ms 10192 KB Output is correct
37 Correct 1122 ms 10292 KB Output is correct
38 Correct 1105 ms 10104 KB Output is correct
39 Correct 22 ms 5496 KB Output is correct
40 Correct 22 ms 5368 KB Output is correct
41 Correct 23 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 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 5488 KB Output is correct
49 Correct 22 ms 5496 KB Output is correct
50 Correct 22 ms 5500 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 5468 KB Output is correct
54 Correct 15 ms 5112 KB Output is correct
55 Correct 15 ms 5116 KB Output is correct
56 Correct 15 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 Correct 1917 ms 10200 KB Output is correct
60 Correct 1867 ms 10216 KB Output is correct
61 Correct 1970 ms 10216 KB Output is correct
62 Correct 1878 ms 10192 KB Output is correct
63 Correct 1897 ms 10348 KB Output is correct
64 Execution timed out 2029 ms 10276 KB Time limit exceeded
65 Halted 0 ms 0 KB -