Submission #105940

# Submission time Handle Problem Language Result Execution time Memory
105940 2019-04-15T19:38:54 Z Kastanda Boat (APIO16_boat) C++11
100 / 100
961 ms 6648 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 515, Mod = 1e9 + 7;
int n, m, A[N], B[N], dp[N + N][N], I[N];
long long F[N + N][N];
pair < int , int > P[N + N];
vector < int > U;
inline void Add(int &a, int b)
{
    a += b;
    if (a >= Mod)
        a -= Mod;
    if (a < 0)
        a += Mod;
}
inline int Power(int a, int b)
{
    int ret = 1;
    for (; b; b >>= 1, a = 1LL * a * a % Mod)
        if (b & 1) ret = 1LL * ret * a % Mod;
    return (ret);
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d%d", &A[i], &B[i]);
        U.pb(A[i]); U.pb(B[i] + 1);
    }
    U.pb(0); U.pb(1);
    sort(U.begin(), U.end());
    U.resize(unique(U.begin(), U.end()) - U.begin());
    for (int i = 0; i < (int)U.size() - 1; i++)
        P[m ++] = {U[i], U[i + 1] - 1};
    reverse(P, P + m);

    for (int i = I[0] = 1; i < N; i++)
        I[i] = I[i - 1] * 1LL * Power(i, Mod - 2) % Mod;
    for (int i = 0; i < m; i++)
    {
        int len = P[i].second - P[i].first + 1;
        for (int lev = 0; lev <= n; lev ++)
        {
            long long vl = 1;
            for (int h = 1; h <= lev + 1; h ++)
                vl = vl * (len + lev - h + 1) % Mod;
            F[i][lev] = vl * I[lev + 1] % Mod;
        }
    }

    for (int i = 0; i <= n; i++)
        dp[m - 1][i] = 1;
    for (int k = 1; k <= n; k ++)
    {
        int sum = 0;
        for (int i = 1; i < m; i ++)
            Add(sum, dp[i][0]);
        for (int i = 0; i < m; i ++, Add(sum, - dp[i][0]))
            if (A[k] <= P[i].first && P[i].second <= B[k])
                for (int j = 0; j <= n; j ++)
                    dp[i][j] = (dp[i][j + 1] + F[i][j] * sum) % Mod;
    }
    int tot = 0;
    for (int i = 0; i < m - 1; i++)
        Add(tot, dp[i][0]);
    return !printf("%d\n", tot);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:26: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", &A[i], &B[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 661 ms 6364 KB Output is correct
2 Correct 699 ms 6480 KB Output is correct
3 Correct 678 ms 6448 KB Output is correct
4 Correct 656 ms 6520 KB Output is correct
5 Correct 667 ms 6452 KB Output is correct
6 Correct 654 ms 6648 KB Output is correct
7 Correct 654 ms 6580 KB Output is correct
8 Correct 651 ms 6312 KB Output is correct
9 Correct 661 ms 6548 KB Output is correct
10 Correct 657 ms 6456 KB Output is correct
11 Correct 648 ms 6520 KB Output is correct
12 Correct 662 ms 6412 KB Output is correct
13 Correct 682 ms 6436 KB Output is correct
14 Correct 675 ms 6568 KB Output is correct
15 Correct 673 ms 6440 KB Output is correct
16 Correct 121 ms 1448 KB Output is correct
17 Correct 129 ms 1528 KB Output is correct
18 Correct 124 ms 1492 KB Output is correct
19 Correct 128 ms 1568 KB Output is correct
20 Correct 124 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 661 ms 6364 KB Output is correct
2 Correct 699 ms 6480 KB Output is correct
3 Correct 678 ms 6448 KB Output is correct
4 Correct 656 ms 6520 KB Output is correct
5 Correct 667 ms 6452 KB Output is correct
6 Correct 654 ms 6648 KB Output is correct
7 Correct 654 ms 6580 KB Output is correct
8 Correct 651 ms 6312 KB Output is correct
9 Correct 661 ms 6548 KB Output is correct
10 Correct 657 ms 6456 KB Output is correct
11 Correct 648 ms 6520 KB Output is correct
12 Correct 662 ms 6412 KB Output is correct
13 Correct 682 ms 6436 KB Output is correct
14 Correct 675 ms 6568 KB Output is correct
15 Correct 673 ms 6440 KB Output is correct
16 Correct 121 ms 1448 KB Output is correct
17 Correct 129 ms 1528 KB Output is correct
18 Correct 124 ms 1492 KB Output is correct
19 Correct 128 ms 1568 KB Output is correct
20 Correct 124 ms 1400 KB Output is correct
21 Correct 754 ms 5948 KB Output is correct
22 Correct 746 ms 6064 KB Output is correct
23 Correct 720 ms 5972 KB Output is correct
24 Correct 771 ms 5856 KB Output is correct
25 Correct 730 ms 5836 KB Output is correct
26 Correct 769 ms 5880 KB Output is correct
27 Correct 812 ms 6116 KB Output is correct
28 Correct 813 ms 5552 KB Output is correct
29 Correct 821 ms 5752 KB Output is correct
30 Correct 654 ms 6348 KB Output is correct
31 Correct 674 ms 6528 KB Output is correct
32 Correct 666 ms 6584 KB Output is correct
33 Correct 670 ms 6584 KB Output is correct
34 Correct 651 ms 6396 KB Output is correct
35 Correct 656 ms 6364 KB Output is correct
36 Correct 662 ms 6492 KB Output is correct
37 Correct 665 ms 6488 KB Output is correct
38 Correct 664 ms 6500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1536 KB Output is correct
2 Correct 10 ms 1536 KB Output is correct
3 Correct 10 ms 1536 KB Output is correct
4 Correct 10 ms 1536 KB Output is correct
5 Correct 10 ms 1536 KB Output is correct
6 Correct 11 ms 1536 KB Output is correct
7 Correct 11 ms 1536 KB Output is correct
8 Correct 11 ms 1608 KB Output is correct
9 Correct 11 ms 1536 KB Output is correct
10 Correct 11 ms 1536 KB Output is correct
11 Correct 11 ms 1656 KB Output is correct
12 Correct 10 ms 1536 KB Output is correct
13 Correct 10 ms 1536 KB Output is correct
14 Correct 10 ms 1536 KB Output is correct
15 Correct 10 ms 1536 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 8 ms 1024 KB Output is correct
18 Correct 7 ms 1024 KB Output is correct
19 Correct 8 ms 1024 KB Output is correct
20 Correct 6 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 661 ms 6364 KB Output is correct
2 Correct 699 ms 6480 KB Output is correct
3 Correct 678 ms 6448 KB Output is correct
4 Correct 656 ms 6520 KB Output is correct
5 Correct 667 ms 6452 KB Output is correct
6 Correct 654 ms 6648 KB Output is correct
7 Correct 654 ms 6580 KB Output is correct
8 Correct 651 ms 6312 KB Output is correct
9 Correct 661 ms 6548 KB Output is correct
10 Correct 657 ms 6456 KB Output is correct
11 Correct 648 ms 6520 KB Output is correct
12 Correct 662 ms 6412 KB Output is correct
13 Correct 682 ms 6436 KB Output is correct
14 Correct 675 ms 6568 KB Output is correct
15 Correct 673 ms 6440 KB Output is correct
16 Correct 121 ms 1448 KB Output is correct
17 Correct 129 ms 1528 KB Output is correct
18 Correct 124 ms 1492 KB Output is correct
19 Correct 128 ms 1568 KB Output is correct
20 Correct 124 ms 1400 KB Output is correct
21 Correct 754 ms 5948 KB Output is correct
22 Correct 746 ms 6064 KB Output is correct
23 Correct 720 ms 5972 KB Output is correct
24 Correct 771 ms 5856 KB Output is correct
25 Correct 730 ms 5836 KB Output is correct
26 Correct 769 ms 5880 KB Output is correct
27 Correct 812 ms 6116 KB Output is correct
28 Correct 813 ms 5552 KB Output is correct
29 Correct 821 ms 5752 KB Output is correct
30 Correct 654 ms 6348 KB Output is correct
31 Correct 674 ms 6528 KB Output is correct
32 Correct 666 ms 6584 KB Output is correct
33 Correct 670 ms 6584 KB Output is correct
34 Correct 651 ms 6396 KB Output is correct
35 Correct 656 ms 6364 KB Output is correct
36 Correct 662 ms 6492 KB Output is correct
37 Correct 665 ms 6488 KB Output is correct
38 Correct 664 ms 6500 KB Output is correct
39 Correct 10 ms 1536 KB Output is correct
40 Correct 10 ms 1536 KB Output is correct
41 Correct 10 ms 1536 KB Output is correct
42 Correct 10 ms 1536 KB Output is correct
43 Correct 10 ms 1536 KB Output is correct
44 Correct 11 ms 1536 KB Output is correct
45 Correct 11 ms 1536 KB Output is correct
46 Correct 11 ms 1608 KB Output is correct
47 Correct 11 ms 1536 KB Output is correct
48 Correct 11 ms 1536 KB Output is correct
49 Correct 11 ms 1656 KB Output is correct
50 Correct 10 ms 1536 KB Output is correct
51 Correct 10 ms 1536 KB Output is correct
52 Correct 10 ms 1536 KB Output is correct
53 Correct 10 ms 1536 KB Output is correct
54 Correct 6 ms 1024 KB Output is correct
55 Correct 8 ms 1024 KB Output is correct
56 Correct 7 ms 1024 KB Output is correct
57 Correct 8 ms 1024 KB Output is correct
58 Correct 6 ms 1024 KB Output is correct
59 Correct 800 ms 6460 KB Output is correct
60 Correct 809 ms 6392 KB Output is correct
61 Correct 822 ms 6508 KB Output is correct
62 Correct 830 ms 6472 KB Output is correct
63 Correct 859 ms 6640 KB Output is correct
64 Correct 941 ms 6436 KB Output is correct
65 Correct 884 ms 6392 KB Output is correct
66 Correct 961 ms 6468 KB Output is correct
67 Correct 908 ms 6392 KB Output is correct
68 Correct 913 ms 6448 KB Output is correct
69 Correct 835 ms 6568 KB Output is correct
70 Correct 790 ms 6580 KB Output is correct
71 Correct 807 ms 6392 KB Output is correct
72 Correct 845 ms 6496 KB Output is correct
73 Correct 846 ms 6500 KB Output is correct
74 Correct 168 ms 1528 KB Output is correct
75 Correct 184 ms 1532 KB Output is correct
76 Correct 154 ms 1640 KB Output is correct
77 Correct 150 ms 1524 KB Output is correct
78 Correct 172 ms 1508 KB Output is correct