답안 #105945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105945 2019-04-15T19:46:26 Z Kastanda Boat (APIO16_boat) C++11
100 / 100
373 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];
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 = 0; i < m; i++)
    {
        int len = P[i].second - P[i].first + 1;
        F[i][0] = len;
        for (int lev = 1; lev <= n; lev ++)
            F[i][lev] = 1LL * F[i][lev - 1] * (len + lev) % Mod * Power(lev + 1, Mod - 2) % 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]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 6392 KB Output is correct
2 Correct 96 ms 6392 KB Output is correct
3 Correct 97 ms 6392 KB Output is correct
4 Correct 102 ms 6356 KB Output is correct
5 Correct 98 ms 6364 KB Output is correct
6 Correct 99 ms 6392 KB Output is correct
7 Correct 98 ms 6364 KB Output is correct
8 Correct 98 ms 6392 KB Output is correct
9 Correct 97 ms 6324 KB Output is correct
10 Correct 100 ms 6432 KB Output is correct
11 Correct 97 ms 6392 KB Output is correct
12 Correct 97 ms 6392 KB Output is correct
13 Correct 98 ms 6360 KB Output is correct
14 Correct 99 ms 6364 KB Output is correct
15 Correct 97 ms 6392 KB Output is correct
16 Correct 19 ms 1408 KB Output is correct
17 Correct 21 ms 1528 KB Output is correct
18 Correct 20 ms 1536 KB Output is correct
19 Correct 21 ms 1528 KB Output is correct
20 Correct 20 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 6392 KB Output is correct
2 Correct 96 ms 6392 KB Output is correct
3 Correct 97 ms 6392 KB Output is correct
4 Correct 102 ms 6356 KB Output is correct
5 Correct 98 ms 6364 KB Output is correct
6 Correct 99 ms 6392 KB Output is correct
7 Correct 98 ms 6364 KB Output is correct
8 Correct 98 ms 6392 KB Output is correct
9 Correct 97 ms 6324 KB Output is correct
10 Correct 100 ms 6432 KB Output is correct
11 Correct 97 ms 6392 KB Output is correct
12 Correct 97 ms 6392 KB Output is correct
13 Correct 98 ms 6360 KB Output is correct
14 Correct 99 ms 6364 KB Output is correct
15 Correct 97 ms 6392 KB Output is correct
16 Correct 19 ms 1408 KB Output is correct
17 Correct 21 ms 1528 KB Output is correct
18 Correct 20 ms 1536 KB Output is correct
19 Correct 21 ms 1528 KB Output is correct
20 Correct 20 ms 1536 KB Output is correct
21 Correct 245 ms 6004 KB Output is correct
22 Correct 238 ms 6008 KB Output is correct
23 Correct 228 ms 5872 KB Output is correct
24 Correct 233 ms 6008 KB Output is correct
25 Correct 231 ms 5864 KB Output is correct
26 Correct 300 ms 5752 KB Output is correct
27 Correct 310 ms 5896 KB Output is correct
28 Correct 333 ms 5620 KB Output is correct
29 Correct 287 ms 5728 KB Output is correct
30 Correct 103 ms 6492 KB Output is correct
31 Correct 98 ms 6364 KB Output is correct
32 Correct 103 ms 6404 KB Output is correct
33 Correct 100 ms 6484 KB Output is correct
34 Correct 101 ms 6392 KB Output is correct
35 Correct 98 ms 6520 KB Output is correct
36 Correct 98 ms 6392 KB Output is correct
37 Correct 103 ms 6376 KB Output is correct
38 Correct 99 ms 6392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1536 KB Output is correct
2 Correct 8 ms 1536 KB Output is correct
3 Correct 8 ms 1536 KB Output is correct
4 Correct 8 ms 1536 KB Output is correct
5 Correct 8 ms 1536 KB Output is correct
6 Correct 8 ms 1536 KB Output is correct
7 Correct 8 ms 1536 KB Output is correct
8 Correct 9 ms 1536 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 9 ms 1508 KB Output is correct
11 Correct 9 ms 1536 KB Output is correct
12 Correct 8 ms 1536 KB Output is correct
13 Correct 9 ms 1536 KB Output is correct
14 Correct 9 ms 1536 KB Output is correct
15 Correct 8 ms 1536 KB Output is correct
16 Correct 7 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 5 ms 1024 KB Output is correct
19 Correct 6 ms 1024 KB Output is correct
20 Correct 6 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 6392 KB Output is correct
2 Correct 96 ms 6392 KB Output is correct
3 Correct 97 ms 6392 KB Output is correct
4 Correct 102 ms 6356 KB Output is correct
5 Correct 98 ms 6364 KB Output is correct
6 Correct 99 ms 6392 KB Output is correct
7 Correct 98 ms 6364 KB Output is correct
8 Correct 98 ms 6392 KB Output is correct
9 Correct 97 ms 6324 KB Output is correct
10 Correct 100 ms 6432 KB Output is correct
11 Correct 97 ms 6392 KB Output is correct
12 Correct 97 ms 6392 KB Output is correct
13 Correct 98 ms 6360 KB Output is correct
14 Correct 99 ms 6364 KB Output is correct
15 Correct 97 ms 6392 KB Output is correct
16 Correct 19 ms 1408 KB Output is correct
17 Correct 21 ms 1528 KB Output is correct
18 Correct 20 ms 1536 KB Output is correct
19 Correct 21 ms 1528 KB Output is correct
20 Correct 20 ms 1536 KB Output is correct
21 Correct 245 ms 6004 KB Output is correct
22 Correct 238 ms 6008 KB Output is correct
23 Correct 228 ms 5872 KB Output is correct
24 Correct 233 ms 6008 KB Output is correct
25 Correct 231 ms 5864 KB Output is correct
26 Correct 300 ms 5752 KB Output is correct
27 Correct 310 ms 5896 KB Output is correct
28 Correct 333 ms 5620 KB Output is correct
29 Correct 287 ms 5728 KB Output is correct
30 Correct 103 ms 6492 KB Output is correct
31 Correct 98 ms 6364 KB Output is correct
32 Correct 103 ms 6404 KB Output is correct
33 Correct 100 ms 6484 KB Output is correct
34 Correct 101 ms 6392 KB Output is correct
35 Correct 98 ms 6520 KB Output is correct
36 Correct 98 ms 6392 KB Output is correct
37 Correct 103 ms 6376 KB Output is correct
38 Correct 99 ms 6392 KB Output is correct
39 Correct 8 ms 1536 KB Output is correct
40 Correct 8 ms 1536 KB Output is correct
41 Correct 8 ms 1536 KB Output is correct
42 Correct 8 ms 1536 KB Output is correct
43 Correct 8 ms 1536 KB Output is correct
44 Correct 8 ms 1536 KB Output is correct
45 Correct 8 ms 1536 KB Output is correct
46 Correct 9 ms 1536 KB Output is correct
47 Correct 9 ms 1536 KB Output is correct
48 Correct 9 ms 1508 KB Output is correct
49 Correct 9 ms 1536 KB Output is correct
50 Correct 8 ms 1536 KB Output is correct
51 Correct 9 ms 1536 KB Output is correct
52 Correct 9 ms 1536 KB Output is correct
53 Correct 8 ms 1536 KB Output is correct
54 Correct 7 ms 1024 KB Output is correct
55 Correct 5 ms 1024 KB Output is correct
56 Correct 5 ms 1024 KB Output is correct
57 Correct 6 ms 1024 KB Output is correct
58 Correct 6 ms 1152 KB Output is correct
59 Correct 259 ms 6540 KB Output is correct
60 Correct 243 ms 6520 KB Output is correct
61 Correct 330 ms 6648 KB Output is correct
62 Correct 289 ms 6476 KB Output is correct
63 Correct 311 ms 6460 KB Output is correct
64 Correct 321 ms 6520 KB Output is correct
65 Correct 336 ms 6520 KB Output is correct
66 Correct 373 ms 6520 KB Output is correct
67 Correct 335 ms 6520 KB Output is correct
68 Correct 362 ms 6428 KB Output is correct
69 Correct 256 ms 6392 KB Output is correct
70 Correct 312 ms 6364 KB Output is correct
71 Correct 318 ms 6520 KB Output is correct
72 Correct 318 ms 6520 KB Output is correct
73 Correct 246 ms 6392 KB Output is correct
74 Correct 48 ms 1408 KB Output is correct
75 Correct 51 ms 1528 KB Output is correct
76 Correct 49 ms 1528 KB Output is correct
77 Correct 68 ms 1528 KB Output is correct
78 Correct 48 ms 1528 KB Output is correct