Submission #218147

# Submission time Handle Problem Language Result Execution time Memory
218147 2020-04-01T10:24:51 Z SamAnd Boat (APIO16_boat) C++17
9 / 100
902 ms 14328 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
const int M = 1000000007;

int ast(int x, int n)
{
    int ans = 1;
    while (n)
    {
        if (n % 2 == 1)
            ans = (ans * 1LL * x) % M;
        x = (x * 1LL * x) % M;
        n /= 2;
    }
    return ans;
}

int n;
int l[N], r[N];

vector<int> v;
int c[N][N];
int pc[N][N];

int dp[N][N];
int p[N][N];
int pp[N][N];

int ans;
void rec(int i)
{
    if (i == n + 1)
    {
        if (!v.empty())
            ++ans;
        return;
    }
    rec(i + 1);
    for (int j = l[i]; j <= r[i]; ++j)
    {
        if (v.empty() || v.back() < j)
        {
            v.push_back(j);
            rec(i + 1);
            v.pop_back();
        }
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d%d", &l[i], &r[i]);
        v.push_back(l[i]);
        v.push_back(r[i] + 1);
    }
    sort(v.begin(), v.end());
    vector<int> vv;
    for (int i = 0; i < v.size(); ++i)
    {
        if (!i || v[i] != v[i - 1])
            vv.push_back(v[i]);
    }
    v = vv;
    for (int i = 0; i < v.size() - 1; ++i)
    {
        for (int k = 0; k <= n; ++k)
        {
            c[i][k] = 1;
            int f = 1;
            for (int j = 1; j <= k; ++j)
            {
                c[i][k] = (c[i][k] * 1LL * (v[i + 1] - v[i] - j + 1)) % M;
                f = (f * 1LL * j) % M;
            }
            c[i][k] = (c[i][k] * 1LL * ast(f, M - 2)) % M;
            if (k > 1)
                pc[i][k] = (pc[i][k - 1] + c[i][k]) % M;
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < v.size() - 1; ++j)
        {
            if (!(l[i] <= v[j] && v[j + 1] - 1 <= r[i]))
                continue;
            int q = 0;
            for (int k = i; k >= 1; --k)
            {
                if (!(l[k] <= v[j] && v[j + 1] - 1 <= r[k]))
                    continue;
                ++q;
                if (k - 1 == 0 || j - 1 == -1)
                {
                    if (i == k)
                        dp[i][j] = (dp[i][j] + c[j][q]) % M;
                    else
                        dp[i][j] = (dp[i][j] + pc[j][q]) % M;
                }
                else
                {
                    if (i == k)
                        dp[i][j] = (dp[i][j] + (pp[k - 1][j - 1] + 1) * 1LL * c[j][q]) % M;
                    else
                        dp[i][j] = (dp[i][j] + (pp[k - 1][j - 1] + 1) * 1LL * pc[j][q]) % M;
                }
            }
        }
        for (int j = 0; j < v.size() - 1; ++j)
        {
            p[i][j] = (p[i - 1][j] + dp[i][j]) % M;
        }
        pp[i][0] = p[i][0];
        for (int j = 1; j < v.size() - 1; ++j)
            pp[i][j] = (pp[i][j - 1] + p[i][j]) % M;
    }
    printf("%d\n", pp[n][v.size() - 2]);
    //v.clear();
    //rec(1);
    //printf("%d\n", ans);
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:63:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
boat.cpp:69:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size() - 1; ++i)
                     ~~^~~~~~~~~~~~~~
boat.cpp:87:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v.size() - 1; ++j)
                         ~~^~~~~~~~~~~~~~
boat.cpp:113:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v.size() - 1; ++j)
                         ~~^~~~~~~~~~~~~~
boat.cpp:118:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 1; j < v.size() - 1; ++j)
                         ~~^~~~~~~~~~~~~~
boat.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:57: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 841 ms 13728 KB Output is correct
2 Correct 846 ms 13792 KB Output is correct
3 Correct 846 ms 13740 KB Output is correct
4 Correct 833 ms 13816 KB Output is correct
5 Correct 831 ms 13936 KB Output is correct
6 Correct 847 ms 14036 KB Output is correct
7 Correct 826 ms 14072 KB Output is correct
8 Correct 837 ms 14244 KB Output is correct
9 Correct 828 ms 14116 KB Output is correct
10 Correct 828 ms 14320 KB Output is correct
11 Correct 829 ms 14072 KB Output is correct
12 Correct 835 ms 14072 KB Output is correct
13 Correct 827 ms 14168 KB Output is correct
14 Correct 831 ms 14200 KB Output is correct
15 Correct 844 ms 14328 KB Output is correct
16 Correct 151 ms 7544 KB Output is correct
17 Correct 162 ms 7672 KB Output is correct
18 Correct 157 ms 7672 KB Output is correct
19 Correct 163 ms 7672 KB Output is correct
20 Correct 158 ms 7604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 841 ms 13728 KB Output is correct
2 Correct 846 ms 13792 KB Output is correct
3 Correct 846 ms 13740 KB Output is correct
4 Correct 833 ms 13816 KB Output is correct
5 Correct 831 ms 13936 KB Output is correct
6 Correct 847 ms 14036 KB Output is correct
7 Correct 826 ms 14072 KB Output is correct
8 Correct 837 ms 14244 KB Output is correct
9 Correct 828 ms 14116 KB Output is correct
10 Correct 828 ms 14320 KB Output is correct
11 Correct 829 ms 14072 KB Output is correct
12 Correct 835 ms 14072 KB Output is correct
13 Correct 827 ms 14168 KB Output is correct
14 Correct 831 ms 14200 KB Output is correct
15 Correct 844 ms 14328 KB Output is correct
16 Correct 151 ms 7544 KB Output is correct
17 Correct 162 ms 7672 KB Output is correct
18 Correct 157 ms 7672 KB Output is correct
19 Correct 163 ms 7672 KB Output is correct
20 Correct 158 ms 7604 KB Output is correct
21 Incorrect 902 ms 13368 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 3072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 841 ms 13728 KB Output is correct
2 Correct 846 ms 13792 KB Output is correct
3 Correct 846 ms 13740 KB Output is correct
4 Correct 833 ms 13816 KB Output is correct
5 Correct 831 ms 13936 KB Output is correct
6 Correct 847 ms 14036 KB Output is correct
7 Correct 826 ms 14072 KB Output is correct
8 Correct 837 ms 14244 KB Output is correct
9 Correct 828 ms 14116 KB Output is correct
10 Correct 828 ms 14320 KB Output is correct
11 Correct 829 ms 14072 KB Output is correct
12 Correct 835 ms 14072 KB Output is correct
13 Correct 827 ms 14168 KB Output is correct
14 Correct 831 ms 14200 KB Output is correct
15 Correct 844 ms 14328 KB Output is correct
16 Correct 151 ms 7544 KB Output is correct
17 Correct 162 ms 7672 KB Output is correct
18 Correct 157 ms 7672 KB Output is correct
19 Correct 163 ms 7672 KB Output is correct
20 Correct 158 ms 7604 KB Output is correct
21 Incorrect 902 ms 13368 KB Output isn't correct
22 Halted 0 ms 0 KB -