답안 #52974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52974 2018-06-27T12:01:04 Z evpipis Boat (APIO16_boat) C++11
100 / 100
1627 ms 10748 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
const int len = 502, mod = 1e9+7;
int n, m = 0;
int po[2*len], dp[2][2*len][len][2], bi[2*len][len], l[len], r[len];
vector<int> vec;

inline int add(int a, int b){
    a += b;
    if (a >= mod) a -= mod;
    return a;
}

inline int mul(int a, int b){
    return (a*1LL*b)%mod;
}

int pw(int a, int b){
    if (b == 0) return 1;
    if (b%2 == 0) return pw(mul(a, a), b/2);
    return mul(a, pw(mul(a, a), b/2));
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        scanf("%d %d", &l[i], &r[i]);
        vec.pb(l[i]), vec.pb(r[i]);
    }

    sort(vec.begin(), vec.end());
    for (int i = 0; i < vec.size(); i++)
        if (vec[i] != po[m])
            po[++m] = vec[i];

    //for (int i = 0; i <= m; i++)
      //  printf("i = %d, poi = %d\n", i, po[i]);

    for (int i = 0; i <= m; i++){
        bi[i][0] = 1;
        int s = po[i]-po[i-1] - 1;
        for (int k = 1; k <= min(s, n); k++)
            bi[i][k] = mul(bi[i][k-1], mul(s-k+1, pw(k, mod-2)));
    }

    for (int j = 0; j <= m+1; j++)
        dp[0][j][0][0] = 1;

    for (int i = 1; i <= n; i++){
        dp[i&1][0][0][0] = 1;

        for (int j = 1; j <= m+1; j++){
            int ans = 0;
            for (int x = 0; x <= i; x++){
                ans = add(ans, mul(dp[i&1][j-1][x][0], bi[j-1][x]));
                ans = add(ans, mul(dp[i&1][j-1][x][1], bi[j-1][x-1]));
            }
            dp[i&1][j][0][0] = ans;

            for (int k = 1; k <= i; k++){
                for (int t = 0; t < 2; t++){
                    ans = dp[(i-1)&1][j][k][t];
                    if (t == 0 && l[i] <= po[j-1]+1 && po[j]-1 <= r[i])
                        ans = add(ans, dp[(i-1)&1][j][k-1][0]);
                    if (t == 1 && l[i] <= po[j] && po[j] <= r[i])
                        ans = add(ans, dp[(i-1)&1][j][k-1][0]);

                    dp[i&1][j][k][t] = ans;
                }
            }
        }
    }

    printf("%d\n", add(dp[n&1][m+1][0][0], mod-1));
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:34:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++)
                     ~~^~~~~~~~~~~~
boat.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &l[i], &r[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 546 ms 5368 KB Output is correct
2 Correct 650 ms 5608 KB Output is correct
3 Correct 552 ms 5608 KB Output is correct
4 Correct 671 ms 5608 KB Output is correct
5 Correct 532 ms 5608 KB Output is correct
6 Correct 562 ms 5656 KB Output is correct
7 Correct 552 ms 5656 KB Output is correct
8 Correct 539 ms 5664 KB Output is correct
9 Correct 591 ms 5680 KB Output is correct
10 Correct 527 ms 5680 KB Output is correct
11 Correct 551 ms 5740 KB Output is correct
12 Correct 523 ms 5740 KB Output is correct
13 Correct 556 ms 5740 KB Output is correct
14 Correct 600 ms 5740 KB Output is correct
15 Correct 594 ms 5756 KB Output is correct
16 Correct 108 ms 5756 KB Output is correct
17 Correct 114 ms 5756 KB Output is correct
18 Correct 98 ms 5756 KB Output is correct
19 Correct 106 ms 5756 KB Output is correct
20 Correct 103 ms 5756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 546 ms 5368 KB Output is correct
2 Correct 650 ms 5608 KB Output is correct
3 Correct 552 ms 5608 KB Output is correct
4 Correct 671 ms 5608 KB Output is correct
5 Correct 532 ms 5608 KB Output is correct
6 Correct 562 ms 5656 KB Output is correct
7 Correct 552 ms 5656 KB Output is correct
8 Correct 539 ms 5664 KB Output is correct
9 Correct 591 ms 5680 KB Output is correct
10 Correct 527 ms 5680 KB Output is correct
11 Correct 551 ms 5740 KB Output is correct
12 Correct 523 ms 5740 KB Output is correct
13 Correct 556 ms 5740 KB Output is correct
14 Correct 600 ms 5740 KB Output is correct
15 Correct 594 ms 5756 KB Output is correct
16 Correct 108 ms 5756 KB Output is correct
17 Correct 114 ms 5756 KB Output is correct
18 Correct 98 ms 5756 KB Output is correct
19 Correct 106 ms 5756 KB Output is correct
20 Correct 103 ms 5756 KB Output is correct
21 Correct 1030 ms 9596 KB Output is correct
22 Correct 1053 ms 9816 KB Output is correct
23 Correct 980 ms 9816 KB Output is correct
24 Correct 1033 ms 9856 KB Output is correct
25 Correct 1036 ms 9856 KB Output is correct
26 Correct 1095 ms 9856 KB Output is correct
27 Correct 1075 ms 9856 KB Output is correct
28 Correct 1026 ms 9856 KB Output is correct
29 Correct 1125 ms 9856 KB Output is correct
30 Correct 1175 ms 10124 KB Output is correct
31 Correct 1204 ms 10124 KB Output is correct
32 Correct 1113 ms 10124 KB Output is correct
33 Correct 1020 ms 10124 KB Output is correct
34 Correct 1089 ms 10124 KB Output is correct
35 Correct 550 ms 10124 KB Output is correct
36 Correct 524 ms 10124 KB Output is correct
37 Correct 558 ms 10124 KB Output is correct
38 Correct 556 ms 10124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 10124 KB Output is correct
2 Correct 18 ms 10124 KB Output is correct
3 Correct 18 ms 10124 KB Output is correct
4 Correct 18 ms 10124 KB Output is correct
5 Correct 18 ms 10124 KB Output is correct
6 Correct 20 ms 10124 KB Output is correct
7 Correct 21 ms 10124 KB Output is correct
8 Correct 21 ms 10124 KB Output is correct
9 Correct 19 ms 10124 KB Output is correct
10 Correct 21 ms 10124 KB Output is correct
11 Correct 18 ms 10124 KB Output is correct
12 Correct 18 ms 10124 KB Output is correct
13 Correct 18 ms 10124 KB Output is correct
14 Correct 19 ms 10124 KB Output is correct
15 Correct 18 ms 10124 KB Output is correct
16 Correct 10 ms 10124 KB Output is correct
17 Correct 9 ms 10124 KB Output is correct
18 Correct 9 ms 10124 KB Output is correct
19 Correct 9 ms 10124 KB Output is correct
20 Correct 10 ms 10124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 546 ms 5368 KB Output is correct
2 Correct 650 ms 5608 KB Output is correct
3 Correct 552 ms 5608 KB Output is correct
4 Correct 671 ms 5608 KB Output is correct
5 Correct 532 ms 5608 KB Output is correct
6 Correct 562 ms 5656 KB Output is correct
7 Correct 552 ms 5656 KB Output is correct
8 Correct 539 ms 5664 KB Output is correct
9 Correct 591 ms 5680 KB Output is correct
10 Correct 527 ms 5680 KB Output is correct
11 Correct 551 ms 5740 KB Output is correct
12 Correct 523 ms 5740 KB Output is correct
13 Correct 556 ms 5740 KB Output is correct
14 Correct 600 ms 5740 KB Output is correct
15 Correct 594 ms 5756 KB Output is correct
16 Correct 108 ms 5756 KB Output is correct
17 Correct 114 ms 5756 KB Output is correct
18 Correct 98 ms 5756 KB Output is correct
19 Correct 106 ms 5756 KB Output is correct
20 Correct 103 ms 5756 KB Output is correct
21 Correct 1030 ms 9596 KB Output is correct
22 Correct 1053 ms 9816 KB Output is correct
23 Correct 980 ms 9816 KB Output is correct
24 Correct 1033 ms 9856 KB Output is correct
25 Correct 1036 ms 9856 KB Output is correct
26 Correct 1095 ms 9856 KB Output is correct
27 Correct 1075 ms 9856 KB Output is correct
28 Correct 1026 ms 9856 KB Output is correct
29 Correct 1125 ms 9856 KB Output is correct
30 Correct 1175 ms 10124 KB Output is correct
31 Correct 1204 ms 10124 KB Output is correct
32 Correct 1113 ms 10124 KB Output is correct
33 Correct 1020 ms 10124 KB Output is correct
34 Correct 1089 ms 10124 KB Output is correct
35 Correct 550 ms 10124 KB Output is correct
36 Correct 524 ms 10124 KB Output is correct
37 Correct 558 ms 10124 KB Output is correct
38 Correct 556 ms 10124 KB Output is correct
39 Correct 18 ms 10124 KB Output is correct
40 Correct 18 ms 10124 KB Output is correct
41 Correct 18 ms 10124 KB Output is correct
42 Correct 18 ms 10124 KB Output is correct
43 Correct 18 ms 10124 KB Output is correct
44 Correct 20 ms 10124 KB Output is correct
45 Correct 21 ms 10124 KB Output is correct
46 Correct 21 ms 10124 KB Output is correct
47 Correct 19 ms 10124 KB Output is correct
48 Correct 21 ms 10124 KB Output is correct
49 Correct 18 ms 10124 KB Output is correct
50 Correct 18 ms 10124 KB Output is correct
51 Correct 18 ms 10124 KB Output is correct
52 Correct 19 ms 10124 KB Output is correct
53 Correct 18 ms 10124 KB Output is correct
54 Correct 10 ms 10124 KB Output is correct
55 Correct 9 ms 10124 KB Output is correct
56 Correct 9 ms 10124 KB Output is correct
57 Correct 9 ms 10124 KB Output is correct
58 Correct 10 ms 10124 KB Output is correct
59 Correct 1314 ms 10572 KB Output is correct
60 Correct 1313 ms 10600 KB Output is correct
61 Correct 1297 ms 10604 KB Output is correct
62 Correct 1320 ms 10604 KB Output is correct
63 Correct 1248 ms 10604 KB Output is correct
64 Correct 1531 ms 10604 KB Output is correct
65 Correct 1359 ms 10620 KB Output is correct
66 Correct 1545 ms 10620 KB Output is correct
67 Correct 1412 ms 10620 KB Output is correct
68 Correct 1627 ms 10620 KB Output is correct
69 Correct 1351 ms 10620 KB Output is correct
70 Correct 1212 ms 10620 KB Output is correct
71 Correct 1208 ms 10748 KB Output is correct
72 Correct 1167 ms 10748 KB Output is correct
73 Correct 1419 ms 10748 KB Output is correct
74 Correct 140 ms 10748 KB Output is correct
75 Correct 147 ms 10748 KB Output is correct
76 Correct 129 ms 10748 KB Output is correct
77 Correct 149 ms 10748 KB Output is correct
78 Correct 125 ms 10748 KB Output is correct