Submission #52972

# Submission time Handle Problem Language Result Execution time Memory
52972 2018-06-27T11:57:48 Z evpipis Boat (APIO16_boat) C++11
58 / 100
2000 ms 10496 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;

int add(int a, int b){
    return (a+b)%mod;
}

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:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++)
                     ~~^~~~~~~~~~~~
boat.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:27: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]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 879 ms 5496 KB Output is correct
2 Correct 838 ms 5736 KB Output is correct
3 Correct 916 ms 5736 KB Output is correct
4 Correct 871 ms 5736 KB Output is correct
5 Correct 845 ms 5736 KB Output is correct
6 Correct 868 ms 5736 KB Output is correct
7 Correct 825 ms 5736 KB Output is correct
8 Correct 876 ms 5736 KB Output is correct
9 Correct 840 ms 5736 KB Output is correct
10 Correct 864 ms 5736 KB Output is correct
11 Correct 841 ms 5736 KB Output is correct
12 Correct 859 ms 5736 KB Output is correct
13 Correct 896 ms 5736 KB Output is correct
14 Correct 933 ms 5736 KB Output is correct
15 Correct 885 ms 5736 KB Output is correct
16 Correct 153 ms 5736 KB Output is correct
17 Correct 167 ms 5736 KB Output is correct
18 Correct 158 ms 5736 KB Output is correct
19 Correct 166 ms 5736 KB Output is correct
20 Correct 161 ms 5736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 879 ms 5496 KB Output is correct
2 Correct 838 ms 5736 KB Output is correct
3 Correct 916 ms 5736 KB Output is correct
4 Correct 871 ms 5736 KB Output is correct
5 Correct 845 ms 5736 KB Output is correct
6 Correct 868 ms 5736 KB Output is correct
7 Correct 825 ms 5736 KB Output is correct
8 Correct 876 ms 5736 KB Output is correct
9 Correct 840 ms 5736 KB Output is correct
10 Correct 864 ms 5736 KB Output is correct
11 Correct 841 ms 5736 KB Output is correct
12 Correct 859 ms 5736 KB Output is correct
13 Correct 896 ms 5736 KB Output is correct
14 Correct 933 ms 5736 KB Output is correct
15 Correct 885 ms 5736 KB Output is correct
16 Correct 153 ms 5736 KB Output is correct
17 Correct 167 ms 5736 KB Output is correct
18 Correct 158 ms 5736 KB Output is correct
19 Correct 166 ms 5736 KB Output is correct
20 Correct 161 ms 5736 KB Output is correct
21 Correct 1852 ms 9724 KB Output is correct
22 Correct 1815 ms 9852 KB Output is correct
23 Correct 1748 ms 9852 KB Output is correct
24 Correct 1969 ms 9852 KB Output is correct
25 Correct 1782 ms 9852 KB Output is correct
26 Correct 1881 ms 9852 KB Output is correct
27 Correct 1918 ms 9852 KB Output is correct
28 Correct 1933 ms 9852 KB Output is correct
29 Correct 1817 ms 9852 KB Output is correct
30 Correct 1686 ms 10108 KB Output is correct
31 Correct 1620 ms 10108 KB Output is correct
32 Correct 1626 ms 10108 KB Output is correct
33 Correct 1576 ms 10108 KB Output is correct
34 Correct 1633 ms 10108 KB Output is correct
35 Correct 903 ms 10108 KB Output is correct
36 Correct 926 ms 10108 KB Output is correct
37 Correct 849 ms 10108 KB Output is correct
38 Correct 851 ms 10108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 10108 KB Output is correct
2 Correct 26 ms 10108 KB Output is correct
3 Correct 25 ms 10108 KB Output is correct
4 Correct 26 ms 10108 KB Output is correct
5 Correct 27 ms 10108 KB Output is correct
6 Correct 26 ms 10108 KB Output is correct
7 Correct 27 ms 10108 KB Output is correct
8 Correct 25 ms 10108 KB Output is correct
9 Correct 25 ms 10108 KB Output is correct
10 Correct 26 ms 10108 KB Output is correct
11 Correct 24 ms 10108 KB Output is correct
12 Correct 24 ms 10108 KB Output is correct
13 Correct 26 ms 10108 KB Output is correct
14 Correct 32 ms 10108 KB Output is correct
15 Correct 27 ms 10108 KB Output is correct
16 Correct 15 ms 10108 KB Output is correct
17 Correct 13 ms 10108 KB Output is correct
18 Correct 16 ms 10108 KB Output is correct
19 Correct 14 ms 10108 KB Output is correct
20 Correct 13 ms 10108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 879 ms 5496 KB Output is correct
2 Correct 838 ms 5736 KB Output is correct
3 Correct 916 ms 5736 KB Output is correct
4 Correct 871 ms 5736 KB Output is correct
5 Correct 845 ms 5736 KB Output is correct
6 Correct 868 ms 5736 KB Output is correct
7 Correct 825 ms 5736 KB Output is correct
8 Correct 876 ms 5736 KB Output is correct
9 Correct 840 ms 5736 KB Output is correct
10 Correct 864 ms 5736 KB Output is correct
11 Correct 841 ms 5736 KB Output is correct
12 Correct 859 ms 5736 KB Output is correct
13 Correct 896 ms 5736 KB Output is correct
14 Correct 933 ms 5736 KB Output is correct
15 Correct 885 ms 5736 KB Output is correct
16 Correct 153 ms 5736 KB Output is correct
17 Correct 167 ms 5736 KB Output is correct
18 Correct 158 ms 5736 KB Output is correct
19 Correct 166 ms 5736 KB Output is correct
20 Correct 161 ms 5736 KB Output is correct
21 Correct 1852 ms 9724 KB Output is correct
22 Correct 1815 ms 9852 KB Output is correct
23 Correct 1748 ms 9852 KB Output is correct
24 Correct 1969 ms 9852 KB Output is correct
25 Correct 1782 ms 9852 KB Output is correct
26 Correct 1881 ms 9852 KB Output is correct
27 Correct 1918 ms 9852 KB Output is correct
28 Correct 1933 ms 9852 KB Output is correct
29 Correct 1817 ms 9852 KB Output is correct
30 Correct 1686 ms 10108 KB Output is correct
31 Correct 1620 ms 10108 KB Output is correct
32 Correct 1626 ms 10108 KB Output is correct
33 Correct 1576 ms 10108 KB Output is correct
34 Correct 1633 ms 10108 KB Output is correct
35 Correct 903 ms 10108 KB Output is correct
36 Correct 926 ms 10108 KB Output is correct
37 Correct 849 ms 10108 KB Output is correct
38 Correct 851 ms 10108 KB Output is correct
39 Correct 25 ms 10108 KB Output is correct
40 Correct 26 ms 10108 KB Output is correct
41 Correct 25 ms 10108 KB Output is correct
42 Correct 26 ms 10108 KB Output is correct
43 Correct 27 ms 10108 KB Output is correct
44 Correct 26 ms 10108 KB Output is correct
45 Correct 27 ms 10108 KB Output is correct
46 Correct 25 ms 10108 KB Output is correct
47 Correct 25 ms 10108 KB Output is correct
48 Correct 26 ms 10108 KB Output is correct
49 Correct 24 ms 10108 KB Output is correct
50 Correct 24 ms 10108 KB Output is correct
51 Correct 26 ms 10108 KB Output is correct
52 Correct 32 ms 10108 KB Output is correct
53 Correct 27 ms 10108 KB Output is correct
54 Correct 15 ms 10108 KB Output is correct
55 Correct 13 ms 10108 KB Output is correct
56 Correct 16 ms 10108 KB Output is correct
57 Correct 14 ms 10108 KB Output is correct
58 Correct 13 ms 10108 KB Output is correct
59 Execution timed out 2047 ms 10496 KB Time limit exceeded
60 Halted 0 ms 0 KB -