답안 #588606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588606 2022-07-03T16:42:20 Z messiuuuuu Boat (APIO16_boat) C++14
31 / 100
228 ms 8404 KB
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e3 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 7;

int n, a[MAXN], b[MAXN];
vector<int> num;

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i];
        num.pb(a[i]);
        num.pb(b[i] + 1);
    }
}

int l[MAXN];
int dp[MAXN][MAXN];

void add(int& a, int b)
{
    a += b;
    if (a > MOD)
        a -= MOD;
}

int comb[MAXN][MAXN];

void Solve()
{
    comb[0][0] = 1;
    for (int i = 1; i < MAXN; i++)
    {
        comb[i][0] = comb[i][i] = 1;
        for (int j = 1; j < i; j++)
            add(comb[i][j], (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD);
    }
    sort(num.begin(), num.end());
    num.erase(unique(num.begin(), num.end()), num.end());
    for (int i = 1; i < num.size(); i++)
    {
        l[i] = num[i] - num[i - 1];
    }
    for (int i = 1; i <= n; i++)
    {
        a[i] = upper_bound(num.begin(), num.end(), a[i]) - num.begin();
        b[i] = upper_bound(num.begin(), num.end(), b[i]) - num.begin();
    }
    for (int i = 0; i < num.size(); i++)
        dp[0][i] = 1;
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = 1;
        for (int j = a[i]; j <= b[i]; j++)
        {
            dp[i][j] = (1ll * dp[i - 1][j - 1] * l[j]) % MOD;
            int cnt = 1;
            for (int k = i - 1; k; k--)
            {
                if (a[k] <= j && j <= b[k])
                {
                    cnt++;
                    add(dp[i][j], 1ll * dp[k - 1][j - 1] * comb[cnt + l[j] - 2][cnt] % MOD);
                }
            }
        }
        for (int j = 1; j < num.size(); j++)
        {
            add(dp[i][j], (1ll * dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD);
        }
    }
    cout << (dp[n][(int)num.size() - 1] - 1 + MOD) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}

Compilation message

boat.cpp: In function 'void Solve()':
boat.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 1; i < num.size(); i++)
      |                     ~~^~~~~~~~~~~~
boat.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = 0; i < num.size(); i++)
      |                     ~~^~~~~~~~~~~~
boat.cpp:77:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for (int j = 1; j < num.size(); j++)
      |                         ~~^~~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6228 KB Output is correct
2 Correct 10 ms 6228 KB Output is correct
3 Correct 9 ms 6212 KB Output is correct
4 Correct 11 ms 6228 KB Output is correct
5 Correct 8 ms 6228 KB Output is correct
6 Correct 9 ms 6228 KB Output is correct
7 Correct 9 ms 6164 KB Output is correct
8 Correct 9 ms 6228 KB Output is correct
9 Correct 9 ms 6228 KB Output is correct
10 Correct 9 ms 6228 KB Output is correct
11 Correct 8 ms 6228 KB Output is correct
12 Correct 8 ms 6228 KB Output is correct
13 Correct 8 ms 6244 KB Output is correct
14 Correct 8 ms 6164 KB Output is correct
15 Correct 9 ms 6228 KB Output is correct
16 Correct 4 ms 6228 KB Output is correct
17 Correct 5 ms 6228 KB Output is correct
18 Correct 5 ms 6228 KB Output is correct
19 Correct 5 ms 6228 KB Output is correct
20 Correct 5 ms 6228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6228 KB Output is correct
2 Correct 10 ms 6228 KB Output is correct
3 Correct 9 ms 6212 KB Output is correct
4 Correct 11 ms 6228 KB Output is correct
5 Correct 8 ms 6228 KB Output is correct
6 Correct 9 ms 6228 KB Output is correct
7 Correct 9 ms 6164 KB Output is correct
8 Correct 9 ms 6228 KB Output is correct
9 Correct 9 ms 6228 KB Output is correct
10 Correct 9 ms 6228 KB Output is correct
11 Correct 8 ms 6228 KB Output is correct
12 Correct 8 ms 6228 KB Output is correct
13 Correct 8 ms 6244 KB Output is correct
14 Correct 8 ms 6164 KB Output is correct
15 Correct 9 ms 6228 KB Output is correct
16 Correct 4 ms 6228 KB Output is correct
17 Correct 5 ms 6228 KB Output is correct
18 Correct 5 ms 6228 KB Output is correct
19 Correct 5 ms 6228 KB Output is correct
20 Correct 5 ms 6228 KB Output is correct
21 Correct 117 ms 6148 KB Output is correct
22 Correct 113 ms 6156 KB Output is correct
23 Correct 99 ms 6272 KB Output is correct
24 Correct 120 ms 6232 KB Output is correct
25 Correct 119 ms 6284 KB Output is correct
26 Correct 199 ms 6224 KB Output is correct
27 Correct 194 ms 6144 KB Output is correct
28 Correct 189 ms 6208 KB Output is correct
29 Correct 228 ms 6172 KB Output is correct
30 Correct 11 ms 6228 KB Output is correct
31 Correct 10 ms 6272 KB Output is correct
32 Correct 9 ms 6256 KB Output is correct
33 Correct 8 ms 6228 KB Output is correct
34 Correct 9 ms 6260 KB Output is correct
35 Correct 10 ms 6228 KB Output is correct
36 Correct 9 ms 6244 KB Output is correct
37 Correct 9 ms 6272 KB Output is correct
38 Correct 9 ms 6228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 8404 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6228 KB Output is correct
2 Correct 10 ms 6228 KB Output is correct
3 Correct 9 ms 6212 KB Output is correct
4 Correct 11 ms 6228 KB Output is correct
5 Correct 8 ms 6228 KB Output is correct
6 Correct 9 ms 6228 KB Output is correct
7 Correct 9 ms 6164 KB Output is correct
8 Correct 9 ms 6228 KB Output is correct
9 Correct 9 ms 6228 KB Output is correct
10 Correct 9 ms 6228 KB Output is correct
11 Correct 8 ms 6228 KB Output is correct
12 Correct 8 ms 6228 KB Output is correct
13 Correct 8 ms 6244 KB Output is correct
14 Correct 8 ms 6164 KB Output is correct
15 Correct 9 ms 6228 KB Output is correct
16 Correct 4 ms 6228 KB Output is correct
17 Correct 5 ms 6228 KB Output is correct
18 Correct 5 ms 6228 KB Output is correct
19 Correct 5 ms 6228 KB Output is correct
20 Correct 5 ms 6228 KB Output is correct
21 Correct 117 ms 6148 KB Output is correct
22 Correct 113 ms 6156 KB Output is correct
23 Correct 99 ms 6272 KB Output is correct
24 Correct 120 ms 6232 KB Output is correct
25 Correct 119 ms 6284 KB Output is correct
26 Correct 199 ms 6224 KB Output is correct
27 Correct 194 ms 6144 KB Output is correct
28 Correct 189 ms 6208 KB Output is correct
29 Correct 228 ms 6172 KB Output is correct
30 Correct 11 ms 6228 KB Output is correct
31 Correct 10 ms 6272 KB Output is correct
32 Correct 9 ms 6256 KB Output is correct
33 Correct 8 ms 6228 KB Output is correct
34 Correct 9 ms 6260 KB Output is correct
35 Correct 10 ms 6228 KB Output is correct
36 Correct 9 ms 6244 KB Output is correct
37 Correct 9 ms 6272 KB Output is correct
38 Correct 9 ms 6228 KB Output is correct
39 Runtime error 6 ms 8404 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -