답안 #558160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558160 2022-05-07T01:24:08 Z Sweezy Boat (APIO16_boat) C++17
100 / 100
366 ms 8268 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=500, M=1e9+7;
int n, a[mxN], b[mxN];
ll dp[mxN+1][2*mxN], c[2*mxN][mxN+1];
vector<int> pts;

inline ll modI(ll a, ll m) {
    return a<=1?a:(1-modI(m%a, a)*m)/a+m;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> a[i] >> b[i], --a[i];
        pts.push_back(a[i]);
        pts.push_back(b[i]);
    }
    sort(pts.begin(), pts.end());
    pts.resize(unique(pts.begin(), pts.end())-pts.begin());
    for(int i=1; i<pts.size(); ++i) {
        c[i][1]=pts[i]-pts[i-1];
        for(int j=2; j<=n; ++j)
            c[i][j]=c[i][j-1]*(pts[i]-pts[i-1]+j-1)%M*modI(j, M)%M;
    }
    for(int i=0; i<pts.size(); ++i)
        dp[0][i]=1;
    for(int i=1; i<=n; ++i) {
        dp[i][0]=1;
        for(int j=1; j<pts.size(); ++j) {
            dp[i][j]=dp[i][j-1];
            for(int k=i, n2=0; k; --k) {
                if(pts[j]>a[k-1]&&pts[j]<=b[k-1]) {
                    ++n2;
                    dp[i][j]+=dp[k-1][j-1]*c[j][n2]%M;
                }
            }
            dp[i][j]%=M;
        }
    }
    cout << dp[n][pts.size()-1]-1;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=1; i<pts.size(); ++i) {
      |                  ~^~~~~~~~~~~
boat.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i=0; i<pts.size(); ++i)
      |                  ~^~~~~~~~~~~
boat.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j=1; j<pts.size(); ++j) {
      |                      ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 297 ms 8064 KB Output is correct
2 Correct 269 ms 8036 KB Output is correct
3 Correct 271 ms 8060 KB Output is correct
4 Correct 271 ms 8120 KB Output is correct
5 Correct 278 ms 8084 KB Output is correct
6 Correct 166 ms 8080 KB Output is correct
7 Correct 183 ms 8052 KB Output is correct
8 Correct 171 ms 8264 KB Output is correct
9 Correct 170 ms 8116 KB Output is correct
10 Correct 164 ms 8156 KB Output is correct
11 Correct 168 ms 8140 KB Output is correct
12 Correct 171 ms 8068 KB Output is correct
13 Correct 173 ms 8156 KB Output is correct
14 Correct 157 ms 8096 KB Output is correct
15 Correct 180 ms 8104 KB Output is correct
16 Correct 60 ms 3652 KB Output is correct
17 Correct 58 ms 3752 KB Output is correct
18 Correct 59 ms 3660 KB Output is correct
19 Correct 57 ms 3816 KB Output is correct
20 Correct 66 ms 3680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 297 ms 8064 KB Output is correct
2 Correct 269 ms 8036 KB Output is correct
3 Correct 271 ms 8060 KB Output is correct
4 Correct 271 ms 8120 KB Output is correct
5 Correct 278 ms 8084 KB Output is correct
6 Correct 166 ms 8080 KB Output is correct
7 Correct 183 ms 8052 KB Output is correct
8 Correct 171 ms 8264 KB Output is correct
9 Correct 170 ms 8116 KB Output is correct
10 Correct 164 ms 8156 KB Output is correct
11 Correct 168 ms 8140 KB Output is correct
12 Correct 171 ms 8068 KB Output is correct
13 Correct 173 ms 8156 KB Output is correct
14 Correct 157 ms 8096 KB Output is correct
15 Correct 180 ms 8104 KB Output is correct
16 Correct 60 ms 3652 KB Output is correct
17 Correct 58 ms 3752 KB Output is correct
18 Correct 59 ms 3660 KB Output is correct
19 Correct 57 ms 3816 KB Output is correct
20 Correct 66 ms 3680 KB Output is correct
21 Correct 319 ms 7788 KB Output is correct
22 Correct 317 ms 7756 KB Output is correct
23 Correct 325 ms 7752 KB Output is correct
24 Correct 338 ms 7684 KB Output is correct
25 Correct 310 ms 7808 KB Output is correct
26 Correct 247 ms 7756 KB Output is correct
27 Correct 253 ms 7760 KB Output is correct
28 Correct 257 ms 7600 KB Output is correct
29 Correct 262 ms 7672 KB Output is correct
30 Correct 183 ms 8140 KB Output is correct
31 Correct 167 ms 8148 KB Output is correct
32 Correct 172 ms 8052 KB Output is correct
33 Correct 168 ms 8136 KB Output is correct
34 Correct 166 ms 8144 KB Output is correct
35 Correct 289 ms 8160 KB Output is correct
36 Correct 279 ms 8140 KB Output is correct
37 Correct 280 ms 8116 KB Output is correct
38 Correct 280 ms 8052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1620 KB Output is correct
2 Correct 6 ms 1620 KB Output is correct
3 Correct 4 ms 1620 KB Output is correct
4 Correct 5 ms 1620 KB Output is correct
5 Correct 5 ms 1604 KB Output is correct
6 Correct 5 ms 1620 KB Output is correct
7 Correct 5 ms 1584 KB Output is correct
8 Correct 5 ms 1620 KB Output is correct
9 Correct 5 ms 1620 KB Output is correct
10 Correct 5 ms 1620 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1620 KB Output is correct
13 Correct 5 ms 1604 KB Output is correct
14 Correct 5 ms 1620 KB Output is correct
15 Correct 5 ms 1620 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 3 ms 1224 KB Output is correct
18 Correct 3 ms 1236 KB Output is correct
19 Correct 3 ms 1220 KB Output is correct
20 Correct 3 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 297 ms 8064 KB Output is correct
2 Correct 269 ms 8036 KB Output is correct
3 Correct 271 ms 8060 KB Output is correct
4 Correct 271 ms 8120 KB Output is correct
5 Correct 278 ms 8084 KB Output is correct
6 Correct 166 ms 8080 KB Output is correct
7 Correct 183 ms 8052 KB Output is correct
8 Correct 171 ms 8264 KB Output is correct
9 Correct 170 ms 8116 KB Output is correct
10 Correct 164 ms 8156 KB Output is correct
11 Correct 168 ms 8140 KB Output is correct
12 Correct 171 ms 8068 KB Output is correct
13 Correct 173 ms 8156 KB Output is correct
14 Correct 157 ms 8096 KB Output is correct
15 Correct 180 ms 8104 KB Output is correct
16 Correct 60 ms 3652 KB Output is correct
17 Correct 58 ms 3752 KB Output is correct
18 Correct 59 ms 3660 KB Output is correct
19 Correct 57 ms 3816 KB Output is correct
20 Correct 66 ms 3680 KB Output is correct
21 Correct 319 ms 7788 KB Output is correct
22 Correct 317 ms 7756 KB Output is correct
23 Correct 325 ms 7752 KB Output is correct
24 Correct 338 ms 7684 KB Output is correct
25 Correct 310 ms 7808 KB Output is correct
26 Correct 247 ms 7756 KB Output is correct
27 Correct 253 ms 7760 KB Output is correct
28 Correct 257 ms 7600 KB Output is correct
29 Correct 262 ms 7672 KB Output is correct
30 Correct 183 ms 8140 KB Output is correct
31 Correct 167 ms 8148 KB Output is correct
32 Correct 172 ms 8052 KB Output is correct
33 Correct 168 ms 8136 KB Output is correct
34 Correct 166 ms 8144 KB Output is correct
35 Correct 289 ms 8160 KB Output is correct
36 Correct 279 ms 8140 KB Output is correct
37 Correct 280 ms 8116 KB Output is correct
38 Correct 280 ms 8052 KB Output is correct
39 Correct 4 ms 1620 KB Output is correct
40 Correct 6 ms 1620 KB Output is correct
41 Correct 4 ms 1620 KB Output is correct
42 Correct 5 ms 1620 KB Output is correct
43 Correct 5 ms 1604 KB Output is correct
44 Correct 5 ms 1620 KB Output is correct
45 Correct 5 ms 1584 KB Output is correct
46 Correct 5 ms 1620 KB Output is correct
47 Correct 5 ms 1620 KB Output is correct
48 Correct 5 ms 1620 KB Output is correct
49 Correct 4 ms 1628 KB Output is correct
50 Correct 4 ms 1620 KB Output is correct
51 Correct 5 ms 1604 KB Output is correct
52 Correct 5 ms 1620 KB Output is correct
53 Correct 5 ms 1620 KB Output is correct
54 Correct 3 ms 1236 KB Output is correct
55 Correct 3 ms 1224 KB Output is correct
56 Correct 3 ms 1236 KB Output is correct
57 Correct 3 ms 1220 KB Output is correct
58 Correct 3 ms 1236 KB Output is correct
59 Correct 366 ms 8156 KB Output is correct
60 Correct 359 ms 8060 KB Output is correct
61 Correct 341 ms 8268 KB Output is correct
62 Correct 335 ms 8108 KB Output is correct
63 Correct 357 ms 8056 KB Output is correct
64 Correct 304 ms 8084 KB Output is correct
65 Correct 326 ms 8096 KB Output is correct
66 Correct 291 ms 8116 KB Output is correct
67 Correct 302 ms 8128 KB Output is correct
68 Correct 305 ms 8056 KB Output is correct
69 Correct 306 ms 8168 KB Output is correct
70 Correct 298 ms 8088 KB Output is correct
71 Correct 318 ms 8260 KB Output is correct
72 Correct 298 ms 8160 KB Output is correct
73 Correct 308 ms 8124 KB Output is correct
74 Correct 81 ms 3700 KB Output is correct
75 Correct 84 ms 3748 KB Output is correct
76 Correct 90 ms 3760 KB Output is correct
77 Correct 81 ms 3768 KB Output is correct
78 Correct 78 ms 3648 KB Output is correct