답안 #152795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152795 2019-09-09T14:13:28 Z mhy908 Boat (APIO16_boat) C++14
100 / 100
620 ms 4508 KB
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
#define llinf 8987654321987654321
#define mod 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
vector<LL> id;
int n;
LL a[1010], b[1010];
LL dp[1010][1010], inv[1010], len[1010];
LL power(LL a, LL b)
{
    if(!b)return 1;
    LL ret=power(a, b/2);
    return b%2?ret*ret%mod*a%mod:ret*ret%mod;
}
int main()
{
    scanf("%d", &n);
    for(int i=1; i<=1000; i++)inv[i]=power(i, mod-2);
    for(int i=1; i<=n; i++){
        scanf("%lld %lld", &a[i], &b[i]);
        id.pb(a[i]-1);
        id.pb(b[i]);
    }
    sort(all(id));
    id.erase(unique(all(id)), id.end());
    for(int i=1; i<=n; i++){
        LL temp=lower_bound(all(id), a[i]-1)+1-id.begin();
        a[i]=temp;
        temp=lower_bound(all(id), b[i])+1-id.begin();
        b[i]=temp;
    }
    int siz=id.size();
    len[1]=id[0];
    for(int i=1; i<=siz; i++)len[i]=id[i-1]-id[i-2];
    for(int i=1;i<=n;i++){
        for(int j=1; j<=siz; j++){
            if(i==1&&a[i]<j&&j<=b[i])dp[i][j]=(dp[i][j]+len[j])%mod;
            else{
                if(a[i]<j&&j<=b[i]){
                    dp[i][j]=(dp[i][j]+len[j]*(1+dp[i-1][j-1]))%mod;
                    int cnt=1;
                    LL sum=len[j]-1;
                    for(int k=i-1; k>=1; k--){
                        if(a[k]<j&&j<=b[k]){
                            cnt++;
                            sum=sum*(len[j]+cnt-2)%mod*inv[cnt]%mod;
                            dp[i][j]=(dp[i][j]+sum+sum*dp[k-1][j-1])%mod;
                        }
                    }
                }
            }
            dp[i][j]=(dp[i][j]+dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+mod)%mod;
        }
    }
    printf("%lld", dp[n][siz]);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &a[i], &b[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4344 KB Output is correct
2 Correct 12 ms 4344 KB Output is correct
3 Correct 13 ms 4344 KB Output is correct
4 Correct 12 ms 4344 KB Output is correct
5 Correct 13 ms 4472 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4344 KB Output is correct
8 Correct 12 ms 4344 KB Output is correct
9 Correct 12 ms 4344 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4444 KB Output is correct
12 Correct 12 ms 4284 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 7 ms 3064 KB Output is correct
17 Correct 7 ms 3064 KB Output is correct
18 Correct 7 ms 3064 KB Output is correct
19 Correct 7 ms 3192 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4344 KB Output is correct
2 Correct 12 ms 4344 KB Output is correct
3 Correct 13 ms 4344 KB Output is correct
4 Correct 12 ms 4344 KB Output is correct
5 Correct 13 ms 4472 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4344 KB Output is correct
8 Correct 12 ms 4344 KB Output is correct
9 Correct 12 ms 4344 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4444 KB Output is correct
12 Correct 12 ms 4284 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 7 ms 3064 KB Output is correct
17 Correct 7 ms 3064 KB Output is correct
18 Correct 7 ms 3064 KB Output is correct
19 Correct 7 ms 3192 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
21 Correct 251 ms 4316 KB Output is correct
22 Correct 243 ms 4304 KB Output is correct
23 Correct 213 ms 4348 KB Output is correct
24 Correct 238 ms 4316 KB Output is correct
25 Correct 244 ms 4388 KB Output is correct
26 Correct 540 ms 4292 KB Output is correct
27 Correct 554 ms 4332 KB Output is correct
28 Correct 540 ms 4504 KB Output is correct
29 Correct 532 ms 4372 KB Output is correct
30 Correct 12 ms 4344 KB Output is correct
31 Correct 13 ms 4344 KB Output is correct
32 Correct 12 ms 4344 KB Output is correct
33 Correct 12 ms 4344 KB Output is correct
34 Correct 12 ms 4344 KB Output is correct
35 Correct 14 ms 4344 KB Output is correct
36 Correct 14 ms 4344 KB Output is correct
37 Correct 14 ms 4344 KB Output is correct
38 Correct 13 ms 4300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 888 KB Output is correct
2 Correct 5 ms 888 KB Output is correct
3 Correct 5 ms 888 KB Output is correct
4 Correct 5 ms 888 KB Output is correct
5 Correct 5 ms 888 KB Output is correct
6 Correct 8 ms 888 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 8 ms 888 KB Output is correct
9 Correct 8 ms 892 KB Output is correct
10 Correct 8 ms 888 KB Output is correct
11 Correct 6 ms 888 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 888 KB Output is correct
15 Correct 5 ms 888 KB Output is correct
16 Correct 5 ms 888 KB Output is correct
17 Correct 4 ms 760 KB Output is correct
18 Correct 4 ms 764 KB Output is correct
19 Correct 4 ms 888 KB Output is correct
20 Correct 4 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4344 KB Output is correct
2 Correct 12 ms 4344 KB Output is correct
3 Correct 13 ms 4344 KB Output is correct
4 Correct 12 ms 4344 KB Output is correct
5 Correct 13 ms 4472 KB Output is correct
6 Correct 12 ms 4344 KB Output is correct
7 Correct 12 ms 4344 KB Output is correct
8 Correct 12 ms 4344 KB Output is correct
9 Correct 12 ms 4344 KB Output is correct
10 Correct 12 ms 4344 KB Output is correct
11 Correct 12 ms 4444 KB Output is correct
12 Correct 12 ms 4284 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 7 ms 3064 KB Output is correct
17 Correct 7 ms 3064 KB Output is correct
18 Correct 7 ms 3064 KB Output is correct
19 Correct 7 ms 3192 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
21 Correct 251 ms 4316 KB Output is correct
22 Correct 243 ms 4304 KB Output is correct
23 Correct 213 ms 4348 KB Output is correct
24 Correct 238 ms 4316 KB Output is correct
25 Correct 244 ms 4388 KB Output is correct
26 Correct 540 ms 4292 KB Output is correct
27 Correct 554 ms 4332 KB Output is correct
28 Correct 540 ms 4504 KB Output is correct
29 Correct 532 ms 4372 KB Output is correct
30 Correct 12 ms 4344 KB Output is correct
31 Correct 13 ms 4344 KB Output is correct
32 Correct 12 ms 4344 KB Output is correct
33 Correct 12 ms 4344 KB Output is correct
34 Correct 12 ms 4344 KB Output is correct
35 Correct 14 ms 4344 KB Output is correct
36 Correct 14 ms 4344 KB Output is correct
37 Correct 14 ms 4344 KB Output is correct
38 Correct 13 ms 4300 KB Output is correct
39 Correct 6 ms 888 KB Output is correct
40 Correct 5 ms 888 KB Output is correct
41 Correct 5 ms 888 KB Output is correct
42 Correct 5 ms 888 KB Output is correct
43 Correct 5 ms 888 KB Output is correct
44 Correct 8 ms 888 KB Output is correct
45 Correct 8 ms 888 KB Output is correct
46 Correct 8 ms 888 KB Output is correct
47 Correct 8 ms 892 KB Output is correct
48 Correct 8 ms 888 KB Output is correct
49 Correct 6 ms 888 KB Output is correct
50 Correct 5 ms 888 KB Output is correct
51 Correct 5 ms 888 KB Output is correct
52 Correct 5 ms 888 KB Output is correct
53 Correct 5 ms 888 KB Output is correct
54 Correct 5 ms 888 KB Output is correct
55 Correct 4 ms 760 KB Output is correct
56 Correct 4 ms 764 KB Output is correct
57 Correct 4 ms 888 KB Output is correct
58 Correct 4 ms 760 KB Output is correct
59 Correct 271 ms 4316 KB Output is correct
60 Correct 244 ms 4344 KB Output is correct
61 Correct 237 ms 4344 KB Output is correct
62 Correct 277 ms 4444 KB Output is correct
63 Correct 260 ms 4300 KB Output is correct
64 Correct 615 ms 4472 KB Output is correct
65 Correct 612 ms 4508 KB Output is correct
66 Correct 615 ms 4472 KB Output is correct
67 Correct 614 ms 4484 KB Output is correct
68 Correct 620 ms 4388 KB Output is correct
69 Correct 234 ms 4368 KB Output is correct
70 Correct 240 ms 4376 KB Output is correct
71 Correct 236 ms 4380 KB Output is correct
72 Correct 242 ms 4472 KB Output is correct
73 Correct 248 ms 4324 KB Output is correct
74 Correct 68 ms 3064 KB Output is correct
75 Correct 58 ms 3064 KB Output is correct
76 Correct 62 ms 3064 KB Output is correct
77 Correct 61 ms 3024 KB Output is correct
78 Correct 63 ms 3064 KB Output is correct