답안 #1118533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118533 2024-11-25T16:07:43 Z lmToT27 Boat (APIO16_boat) C++17
100 / 100
593 ms 8424 KB
#include <bits/stdc++.h>
#define all(dataStructure) dataStructure.begin(),dataStructure.end()

using namespace std;

typedef long long ll;

const int MAX = 5e2 + 3;
const ll MOD[] = {1000000007, 998244353};
const ll mod = 1e9 + 7;

int n, l[MAX], r[MAX];
ll dp[MAX][2 * MAX], C[MAX][2 * MAX];

template <typename dataType>
inline void compress(vector <dataType> &x) {
        sort(all(x));
        x.erase(unique(all(x)), x.end());
}

ll pw(ll a, ll b) {
        ll res = 1;
        for (; b > 0; b >>= 1) {
                if (b & 1) res = res * a % mod;
                a = a * a % mod;
        }
        return res;
}

void Solve() {
        vector <int> val;
        cin >> n;
        for (int i = 1; i <= n; i++) {
                cin >> l[i] >> r[i];
                l[i]--;
                val.push_back(l[i]);
                val.push_back(r[i]);
        }

        compress(val);

        for (int i = 1; i < (int)val.size(); i++) {
                int sz = val[i] - val[i - 1];
                C[0][i] = 1;
                for (int j = 1; j <= n; j++) {
                        C[j][i] = C[j - 1][i] * (sz + j - 1) % mod * pw(j, mod - 2) % mod;
                }
                dp[0][i] = 1;
        }

        dp[0][0] = 1;

        for (int i = 1; i <= n; i++) {
                dp[i][0] = 1;
                for (int j = 1; j < (int)val.size(); j++) {
                        dp[i][j] = dp[i][j - 1];
                        int cnt = 0;
                        for (int k = i; k >= 1; k--) {
                                if (l[k] < val[j] && val[j] <= r[k]) {
                                        cnt++;
                                        dp[i][j] += dp[k - 1][j - 1] * C[cnt][j] % mod;
                                        dp[i][j] %= mod;
                                }
                        }
                }
        }

        cout << dp[n][(int)val.size() - 1] - 1;
}

int32_t main() {
        std::ios_base::sync_with_stdio(0);
        std::cin.tie(0); std::cout.tie(0);

        #define TASK ""
        if (fopen(TASK".INP", "r")) {
                freopen(TASK".INP", "r", stdin);
                freopen(TASK".OUT", "w", stdout);
        }

        if (fopen("TASK.INP", "r")) {
                freopen("TASK.INP", "r", stdin);
                freopen("TASK.OUT", "w", stdout);
        }

        /* int TEST = 1; cin >> TEST; while (TEST--) */ Solve();

        cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
        return 0;
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:77:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |                 freopen(TASK".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:78:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |                 freopen(TASK".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:82:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |                 freopen("TASK.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:83:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |                 freopen("TASK.OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 304 ms 8180 KB Output is correct
2 Correct 249 ms 8280 KB Output is correct
3 Correct 286 ms 8288 KB Output is correct
4 Correct 269 ms 8172 KB Output is correct
5 Correct 279 ms 8120 KB Output is correct
6 Correct 235 ms 8280 KB Output is correct
7 Correct 288 ms 8276 KB Output is correct
8 Correct 254 ms 8276 KB Output is correct
9 Correct 288 ms 8284 KB Output is correct
10 Correct 241 ms 8288 KB Output is correct
11 Correct 263 ms 8272 KB Output is correct
12 Correct 254 ms 8260 KB Output is correct
13 Correct 345 ms 8272 KB Output is correct
14 Correct 230 ms 8264 KB Output is correct
15 Correct 239 ms 8268 KB Output is correct
16 Correct 61 ms 5672 KB Output is correct
17 Correct 80 ms 5744 KB Output is correct
18 Correct 59 ms 6364 KB Output is correct
19 Correct 62 ms 6372 KB Output is correct
20 Correct 61 ms 6424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 304 ms 8180 KB Output is correct
2 Correct 249 ms 8280 KB Output is correct
3 Correct 286 ms 8288 KB Output is correct
4 Correct 269 ms 8172 KB Output is correct
5 Correct 279 ms 8120 KB Output is correct
6 Correct 235 ms 8280 KB Output is correct
7 Correct 288 ms 8276 KB Output is correct
8 Correct 254 ms 8276 KB Output is correct
9 Correct 288 ms 8284 KB Output is correct
10 Correct 241 ms 8288 KB Output is correct
11 Correct 263 ms 8272 KB Output is correct
12 Correct 254 ms 8260 KB Output is correct
13 Correct 345 ms 8272 KB Output is correct
14 Correct 230 ms 8264 KB Output is correct
15 Correct 239 ms 8268 KB Output is correct
16 Correct 61 ms 5672 KB Output is correct
17 Correct 80 ms 5744 KB Output is correct
18 Correct 59 ms 6364 KB Output is correct
19 Correct 62 ms 6372 KB Output is correct
20 Correct 61 ms 6424 KB Output is correct
21 Correct 371 ms 8192 KB Output is correct
22 Correct 356 ms 8340 KB Output is correct
23 Correct 323 ms 8276 KB Output is correct
24 Correct 332 ms 8424 KB Output is correct
25 Correct 355 ms 8200 KB Output is correct
26 Correct 482 ms 8280 KB Output is correct
27 Correct 518 ms 8264 KB Output is correct
28 Correct 513 ms 8296 KB Output is correct
29 Correct 516 ms 8120 KB Output is correct
30 Correct 257 ms 8224 KB Output is correct
31 Correct 327 ms 8220 KB Output is correct
32 Correct 238 ms 8268 KB Output is correct
33 Correct 224 ms 8264 KB Output is correct
34 Correct 263 ms 8272 KB Output is correct
35 Correct 248 ms 8272 KB Output is correct
36 Correct 254 ms 8168 KB Output is correct
37 Correct 259 ms 8280 KB Output is correct
38 Correct 294 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1364 KB Output is correct
2 Correct 7 ms 1360 KB Output is correct
3 Correct 7 ms 1508 KB Output is correct
4 Correct 6 ms 1376 KB Output is correct
5 Correct 8 ms 1376 KB Output is correct
6 Correct 8 ms 1532 KB Output is correct
7 Correct 9 ms 1376 KB Output is correct
8 Correct 10 ms 1376 KB Output is correct
9 Correct 10 ms 1376 KB Output is correct
10 Correct 8 ms 1376 KB Output is correct
11 Correct 7 ms 1376 KB Output is correct
12 Correct 8 ms 1376 KB Output is correct
13 Correct 7 ms 1376 KB Output is correct
14 Correct 7 ms 1468 KB Output is correct
15 Correct 10 ms 1376 KB Output is correct
16 Correct 5 ms 1392 KB Output is correct
17 Correct 5 ms 1376 KB Output is correct
18 Correct 5 ms 1244 KB Output is correct
19 Correct 6 ms 1532 KB Output is correct
20 Correct 5 ms 1376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 304 ms 8180 KB Output is correct
2 Correct 249 ms 8280 KB Output is correct
3 Correct 286 ms 8288 KB Output is correct
4 Correct 269 ms 8172 KB Output is correct
5 Correct 279 ms 8120 KB Output is correct
6 Correct 235 ms 8280 KB Output is correct
7 Correct 288 ms 8276 KB Output is correct
8 Correct 254 ms 8276 KB Output is correct
9 Correct 288 ms 8284 KB Output is correct
10 Correct 241 ms 8288 KB Output is correct
11 Correct 263 ms 8272 KB Output is correct
12 Correct 254 ms 8260 KB Output is correct
13 Correct 345 ms 8272 KB Output is correct
14 Correct 230 ms 8264 KB Output is correct
15 Correct 239 ms 8268 KB Output is correct
16 Correct 61 ms 5672 KB Output is correct
17 Correct 80 ms 5744 KB Output is correct
18 Correct 59 ms 6364 KB Output is correct
19 Correct 62 ms 6372 KB Output is correct
20 Correct 61 ms 6424 KB Output is correct
21 Correct 371 ms 8192 KB Output is correct
22 Correct 356 ms 8340 KB Output is correct
23 Correct 323 ms 8276 KB Output is correct
24 Correct 332 ms 8424 KB Output is correct
25 Correct 355 ms 8200 KB Output is correct
26 Correct 482 ms 8280 KB Output is correct
27 Correct 518 ms 8264 KB Output is correct
28 Correct 513 ms 8296 KB Output is correct
29 Correct 516 ms 8120 KB Output is correct
30 Correct 257 ms 8224 KB Output is correct
31 Correct 327 ms 8220 KB Output is correct
32 Correct 238 ms 8268 KB Output is correct
33 Correct 224 ms 8264 KB Output is correct
34 Correct 263 ms 8272 KB Output is correct
35 Correct 248 ms 8272 KB Output is correct
36 Correct 254 ms 8168 KB Output is correct
37 Correct 259 ms 8280 KB Output is correct
38 Correct 294 ms 8280 KB Output is correct
39 Correct 8 ms 1364 KB Output is correct
40 Correct 7 ms 1360 KB Output is correct
41 Correct 7 ms 1508 KB Output is correct
42 Correct 6 ms 1376 KB Output is correct
43 Correct 8 ms 1376 KB Output is correct
44 Correct 8 ms 1532 KB Output is correct
45 Correct 9 ms 1376 KB Output is correct
46 Correct 10 ms 1376 KB Output is correct
47 Correct 10 ms 1376 KB Output is correct
48 Correct 8 ms 1376 KB Output is correct
49 Correct 7 ms 1376 KB Output is correct
50 Correct 8 ms 1376 KB Output is correct
51 Correct 7 ms 1376 KB Output is correct
52 Correct 7 ms 1468 KB Output is correct
53 Correct 10 ms 1376 KB Output is correct
54 Correct 5 ms 1392 KB Output is correct
55 Correct 5 ms 1376 KB Output is correct
56 Correct 5 ms 1244 KB Output is correct
57 Correct 6 ms 1532 KB Output is correct
58 Correct 5 ms 1376 KB Output is correct
59 Correct 419 ms 8276 KB Output is correct
60 Correct 379 ms 8260 KB Output is correct
61 Correct 351 ms 8268 KB Output is correct
62 Correct 372 ms 8280 KB Output is correct
63 Correct 356 ms 8272 KB Output is correct
64 Correct 565 ms 8148 KB Output is correct
65 Correct 593 ms 8288 KB Output is correct
66 Correct 572 ms 8284 KB Output is correct
67 Correct 588 ms 8220 KB Output is correct
68 Correct 586 ms 8360 KB Output is correct
69 Correct 432 ms 8216 KB Output is correct
70 Correct 445 ms 8164 KB Output is correct
71 Correct 462 ms 8276 KB Output is correct
72 Correct 464 ms 8320 KB Output is correct
73 Correct 473 ms 8224 KB Output is correct
74 Correct 76 ms 5644 KB Output is correct
75 Correct 89 ms 5748 KB Output is correct
76 Correct 76 ms 5708 KB Output is correct
77 Correct 86 ms 5720 KB Output is correct
78 Correct 73 ms 5728 KB Output is correct