답안 #218127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218127 2020-04-01T09:49:06 Z SamAnd Boat (APIO16_boat) C++17
9 / 100
989 ms 14264 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 main()
{
    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());
    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]);
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:40:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size() - 1; ++i)
                     ~~^~~~~~~~~~~~~~
boat.cpp:58:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v.size() - 1; ++j)
                         ~~^~~~~~~~~~~~~~
boat.cpp:84:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v.size() - 1; ++j)
                         ~~^~~~~~~~~~~~~~
boat.cpp:89:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 1; j < v.size() - 1; ++j)
                         ~~^~~~~~~~~~~~~~
boat.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:35: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 823 ms 13816 KB Output is correct
2 Correct 824 ms 13816 KB Output is correct
3 Correct 838 ms 13816 KB Output is correct
4 Correct 828 ms 13720 KB Output is correct
5 Correct 835 ms 13888 KB Output is correct
6 Correct 837 ms 14076 KB Output is correct
7 Correct 824 ms 14072 KB Output is correct
8 Correct 823 ms 14264 KB Output is correct
9 Correct 834 ms 14136 KB Output is correct
10 Correct 846 ms 14076 KB Output is correct
11 Correct 828 ms 14072 KB Output is correct
12 Correct 824 ms 14072 KB Output is correct
13 Correct 832 ms 14132 KB Output is correct
14 Correct 822 ms 14244 KB Output is correct
15 Correct 830 ms 14200 KB Output is correct
16 Correct 849 ms 14076 KB Output is correct
17 Correct 873 ms 13944 KB Output is correct
18 Correct 872 ms 13816 KB Output is correct
19 Correct 825 ms 13816 KB Output is correct
20 Correct 827 ms 13816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 823 ms 13816 KB Output is correct
2 Correct 824 ms 13816 KB Output is correct
3 Correct 838 ms 13816 KB Output is correct
4 Correct 828 ms 13720 KB Output is correct
5 Correct 835 ms 13888 KB Output is correct
6 Correct 837 ms 14076 KB Output is correct
7 Correct 824 ms 14072 KB Output is correct
8 Correct 823 ms 14264 KB Output is correct
9 Correct 834 ms 14136 KB Output is correct
10 Correct 846 ms 14076 KB Output is correct
11 Correct 828 ms 14072 KB Output is correct
12 Correct 824 ms 14072 KB Output is correct
13 Correct 832 ms 14132 KB Output is correct
14 Correct 822 ms 14244 KB Output is correct
15 Correct 830 ms 14200 KB Output is correct
16 Correct 849 ms 14076 KB Output is correct
17 Correct 873 ms 13944 KB Output is correct
18 Correct 872 ms 13816 KB Output is correct
19 Correct 825 ms 13816 KB Output is correct
20 Correct 827 ms 13816 KB Output is correct
21 Incorrect 989 ms 14080 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 3072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 823 ms 13816 KB Output is correct
2 Correct 824 ms 13816 KB Output is correct
3 Correct 838 ms 13816 KB Output is correct
4 Correct 828 ms 13720 KB Output is correct
5 Correct 835 ms 13888 KB Output is correct
6 Correct 837 ms 14076 KB Output is correct
7 Correct 824 ms 14072 KB Output is correct
8 Correct 823 ms 14264 KB Output is correct
9 Correct 834 ms 14136 KB Output is correct
10 Correct 846 ms 14076 KB Output is correct
11 Correct 828 ms 14072 KB Output is correct
12 Correct 824 ms 14072 KB Output is correct
13 Correct 832 ms 14132 KB Output is correct
14 Correct 822 ms 14244 KB Output is correct
15 Correct 830 ms 14200 KB Output is correct
16 Correct 849 ms 14076 KB Output is correct
17 Correct 873 ms 13944 KB Output is correct
18 Correct 872 ms 13816 KB Output is correct
19 Correct 825 ms 13816 KB Output is correct
20 Correct 827 ms 13816 KB Output is correct
21 Incorrect 989 ms 14080 KB Output isn't correct
22 Halted 0 ms 0 KB -