답안 #516316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516316 2022-01-21T05:19:12 Z PeppaPig Boat (APIO16_boat) C++14
100 / 100
581 ms 4384 KB
#include <bits/stdc++.h>
 
#define long long long
 
using namespace std;
 
const int N = 1005;
const int M = 1e9+7;
 
long inv[N];
 
long modpow(long a, long b) {
    long ret = 1;
    for( ; b; b >>= 1) {
        if(b & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}
 
int n, a[N], b[N];
long dp[N][N];
vector<int> coord;
 
int main() {
    for(int i = 1; i < N; i++) inv[i] = modpow(i, M-2);
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d %d", a+i, b+i);
        coord.emplace_back(a[i]);
        coord.emplace_back(++b[i]);
    }
    sort(coord.begin(), coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());
    for(int i = 1; i <= n; i++) {
        a[i] = lower_bound(coord.begin(), coord.end(), a[i]) - coord.begin() + 1;
        b[i] = lower_bound(coord.begin(), coord.end(), b[i]) - coord.begin() + 1;
    }
    for(int i = 0; i < N; i++) dp[0][i] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = a[i]; j < b[i]; j++) {
            long p = coord[j] - coord[j-1], cnt = 1;
            for(int k = i-1; ~k; k--) {
                dp[i][j] = (dp[i][j] + (p * dp[k][j-1]) % M) % M;
                if(a[k] <= j && j < b[k]) {
                    ++cnt;
                    p = (p * (coord[j] - coord[j-1] + cnt - 1)) % M;
                    p = (p * inv[cnt]) % M;
                }
            }
        }
        for(int j = 1; j < N; j++) dp[i][j] = (dp[i][j] + dp[i][j-1]) % M;
    }
    long ans = 0;
    for(int i = 1; i <= n; i++) ans = (ans + dp[i][N-1]) % M;
    printf("%lld\n", ans);
 
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d %d", a+i, b+i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4172 KB Output is correct
2 Correct 7 ms 4172 KB Output is correct
3 Correct 9 ms 4172 KB Output is correct
4 Correct 7 ms 4172 KB Output is correct
5 Correct 7 ms 4172 KB Output is correct
6 Correct 6 ms 4172 KB Output is correct
7 Correct 6 ms 4172 KB Output is correct
8 Correct 6 ms 4220 KB Output is correct
9 Correct 7 ms 4256 KB Output is correct
10 Correct 7 ms 4260 KB Output is correct
11 Correct 7 ms 4172 KB Output is correct
12 Correct 6 ms 4184 KB Output is correct
13 Correct 7 ms 4172 KB Output is correct
14 Correct 6 ms 4160 KB Output is correct
15 Correct 7 ms 4172 KB Output is correct
16 Correct 7 ms 4164 KB Output is correct
17 Correct 7 ms 4152 KB Output is correct
18 Correct 7 ms 4172 KB Output is correct
19 Correct 7 ms 4172 KB Output is correct
20 Correct 7 ms 4172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4172 KB Output is correct
2 Correct 7 ms 4172 KB Output is correct
3 Correct 9 ms 4172 KB Output is correct
4 Correct 7 ms 4172 KB Output is correct
5 Correct 7 ms 4172 KB Output is correct
6 Correct 6 ms 4172 KB Output is correct
7 Correct 6 ms 4172 KB Output is correct
8 Correct 6 ms 4220 KB Output is correct
9 Correct 7 ms 4256 KB Output is correct
10 Correct 7 ms 4260 KB Output is correct
11 Correct 7 ms 4172 KB Output is correct
12 Correct 6 ms 4184 KB Output is correct
13 Correct 7 ms 4172 KB Output is correct
14 Correct 6 ms 4160 KB Output is correct
15 Correct 7 ms 4172 KB Output is correct
16 Correct 7 ms 4164 KB Output is correct
17 Correct 7 ms 4152 KB Output is correct
18 Correct 7 ms 4172 KB Output is correct
19 Correct 7 ms 4172 KB Output is correct
20 Correct 7 ms 4172 KB Output is correct
21 Correct 302 ms 4180 KB Output is correct
22 Correct 271 ms 4164 KB Output is correct
23 Correct 256 ms 4160 KB Output is correct
24 Correct 277 ms 4280 KB Output is correct
25 Correct 273 ms 4220 KB Output is correct
26 Correct 479 ms 4176 KB Output is correct
27 Correct 509 ms 4124 KB Output is correct
28 Correct 482 ms 4384 KB Output is correct
29 Correct 488 ms 4240 KB Output is correct
30 Correct 8 ms 4224 KB Output is correct
31 Correct 8 ms 4236 KB Output is correct
32 Correct 8 ms 4144 KB Output is correct
33 Correct 8 ms 4172 KB Output is correct
34 Correct 9 ms 4248 KB Output is correct
35 Correct 8 ms 4172 KB Output is correct
36 Correct 9 ms 4228 KB Output is correct
37 Correct 10 ms 4172 KB Output is correct
38 Correct 9 ms 4172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1100 KB Output is correct
2 Correct 4 ms 1100 KB Output is correct
3 Correct 4 ms 1072 KB Output is correct
4 Correct 4 ms 1100 KB Output is correct
5 Correct 5 ms 1100 KB Output is correct
6 Correct 6 ms 1112 KB Output is correct
7 Correct 6 ms 1100 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 5 ms 1100 KB Output is correct
10 Correct 7 ms 1100 KB Output is correct
11 Correct 4 ms 1100 KB Output is correct
12 Correct 3 ms 1100 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
14 Correct 3 ms 1100 KB Output is correct
15 Correct 5 ms 1100 KB Output is correct
16 Correct 3 ms 1100 KB Output is correct
17 Correct 3 ms 1100 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 4 ms 1100 KB Output is correct
20 Correct 3 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4172 KB Output is correct
2 Correct 7 ms 4172 KB Output is correct
3 Correct 9 ms 4172 KB Output is correct
4 Correct 7 ms 4172 KB Output is correct
5 Correct 7 ms 4172 KB Output is correct
6 Correct 6 ms 4172 KB Output is correct
7 Correct 6 ms 4172 KB Output is correct
8 Correct 6 ms 4220 KB Output is correct
9 Correct 7 ms 4256 KB Output is correct
10 Correct 7 ms 4260 KB Output is correct
11 Correct 7 ms 4172 KB Output is correct
12 Correct 6 ms 4184 KB Output is correct
13 Correct 7 ms 4172 KB Output is correct
14 Correct 6 ms 4160 KB Output is correct
15 Correct 7 ms 4172 KB Output is correct
16 Correct 7 ms 4164 KB Output is correct
17 Correct 7 ms 4152 KB Output is correct
18 Correct 7 ms 4172 KB Output is correct
19 Correct 7 ms 4172 KB Output is correct
20 Correct 7 ms 4172 KB Output is correct
21 Correct 302 ms 4180 KB Output is correct
22 Correct 271 ms 4164 KB Output is correct
23 Correct 256 ms 4160 KB Output is correct
24 Correct 277 ms 4280 KB Output is correct
25 Correct 273 ms 4220 KB Output is correct
26 Correct 479 ms 4176 KB Output is correct
27 Correct 509 ms 4124 KB Output is correct
28 Correct 482 ms 4384 KB Output is correct
29 Correct 488 ms 4240 KB Output is correct
30 Correct 8 ms 4224 KB Output is correct
31 Correct 8 ms 4236 KB Output is correct
32 Correct 8 ms 4144 KB Output is correct
33 Correct 8 ms 4172 KB Output is correct
34 Correct 9 ms 4248 KB Output is correct
35 Correct 8 ms 4172 KB Output is correct
36 Correct 9 ms 4228 KB Output is correct
37 Correct 10 ms 4172 KB Output is correct
38 Correct 9 ms 4172 KB Output is correct
39 Correct 4 ms 1100 KB Output is correct
40 Correct 4 ms 1100 KB Output is correct
41 Correct 4 ms 1072 KB Output is correct
42 Correct 4 ms 1100 KB Output is correct
43 Correct 5 ms 1100 KB Output is correct
44 Correct 6 ms 1112 KB Output is correct
45 Correct 6 ms 1100 KB Output is correct
46 Correct 6 ms 1100 KB Output is correct
47 Correct 5 ms 1100 KB Output is correct
48 Correct 7 ms 1100 KB Output is correct
49 Correct 4 ms 1100 KB Output is correct
50 Correct 3 ms 1100 KB Output is correct
51 Correct 3 ms 1100 KB Output is correct
52 Correct 3 ms 1100 KB Output is correct
53 Correct 5 ms 1100 KB Output is correct
54 Correct 3 ms 1100 KB Output is correct
55 Correct 3 ms 1100 KB Output is correct
56 Correct 3 ms 1100 KB Output is correct
57 Correct 4 ms 1100 KB Output is correct
58 Correct 3 ms 1100 KB Output is correct
59 Correct 320 ms 4176 KB Output is correct
60 Correct 311 ms 4172 KB Output is correct
61 Correct 271 ms 4192 KB Output is correct
62 Correct 323 ms 4232 KB Output is correct
63 Correct 298 ms 4132 KB Output is correct
64 Correct 581 ms 4148 KB Output is correct
65 Correct 552 ms 4124 KB Output is correct
66 Correct 552 ms 4236 KB Output is correct
67 Correct 559 ms 4360 KB Output is correct
68 Correct 554 ms 4288 KB Output is correct
69 Correct 262 ms 4300 KB Output is correct
70 Correct 270 ms 4164 KB Output is correct
71 Correct 248 ms 4168 KB Output is correct
72 Correct 270 ms 4160 KB Output is correct
73 Correct 263 ms 4240 KB Output is correct
74 Correct 68 ms 4192 KB Output is correct
75 Correct 66 ms 4148 KB Output is correct
76 Correct 75 ms 4312 KB Output is correct
77 Correct 71 ms 4224 KB Output is correct
78 Correct 78 ms 4164 KB Output is correct