답안 #172362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172362 2020-01-01T11:35:13 Z rama_pang Boat (APIO16_boat) C++14
9 / 100
237 ms 2424 KB
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int power(int n, int x) {
    if (x == 0) {
        return 1;
    }
    int res = power(n, x / 2);
    return (long long) res * res % MOD * ((x & 1) ? n : 1) % MOD;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int N;
    cin >> N;

    vector<int> A(N + 1);
    vector<int> B(N + 1);
    vector<int> X;
    vector<int> L;
    vector<int> inv(N + 1);

    for (int i = 1; i <= N; i++) {
        cin >> A[i] >> B[i];
        X.emplace_back(A[i]);
        X.emplace_back(B[i] + 1);
        inv[i] = power(i, MOD - 2); // Fermatt's Little Theorem
    }

    sort(begin(X), end(X));
    X.resize(unique(begin(X), end(X)) - begin(X));

    for (int i = 1; i <= N; i++) {
        A[i] = upper_bound(begin(X), end(X), A[i]) - begin(X);
        B[i] = upper_bound(begin(X), end(X), B[i]) - begin(X);
    }

    L.resize(X.size());
    for (int i = 1; i < X.size(); i++) {
        L[i] = X[i] - X[i - 1];
    }

    vector<vector<int>> DP(N + 1, vector<int>(X.size(), 0));
    
    for (int i = 0; i < X.size(); i++) {
        DP[0][i] = 1;
    }

    for (int i = 1; i <= N; i++) {
        DP[i][0] = 1;
        for (int j = A[i]; j <= B[i]; j++) {
            DP[i][j] = ((long long) L[j] * DP[i - 1][j - 1]) % MOD;
            int cnt = 1, choose = L[j];
            for (int k = i; k > 0; k--) {
                if (A[k] <= j && j <= B[k]) {
                    cnt++;
                    choose = (long long) choose * (L[j] - cnt + 1) % MOD * inv[cnt] % MOD;
                    DP[i][j] = (long long) DP[i][j] + (long long) choose * DP[k - 1][j - 1] % MOD;
                }
            }
        }
        for (int j = 1; j < X.size(); j++) {
            DP[i][j] = ((long long) DP[i][j] + DP[i - 1][j] + DP[i][j - 1] - DP[i - 1][j - 1] + MOD) % MOD;
        }
    }

    cout << (DP[N][X.size() - 1] - 1 + MOD) % MOD << "\n";
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:42:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < X.size(); i++) {
                     ~~^~~~~~~~~~
boat.cpp:48:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < X.size(); i++) {
                     ~~^~~~~~~~~~
boat.cpp:65:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 1; j < X.size(); j++) {
                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 9 ms 2296 KB Output is correct
3 Correct 9 ms 2328 KB Output is correct
4 Correct 9 ms 2424 KB Output is correct
5 Correct 9 ms 2304 KB Output is correct
6 Correct 8 ms 2424 KB Output is correct
7 Correct 8 ms 2296 KB Output is correct
8 Correct 9 ms 2296 KB Output is correct
9 Correct 8 ms 2296 KB Output is correct
10 Correct 8 ms 2296 KB Output is correct
11 Correct 9 ms 2296 KB Output is correct
12 Correct 8 ms 2296 KB Output is correct
13 Correct 8 ms 2296 KB Output is correct
14 Correct 8 ms 2296 KB Output is correct
15 Correct 8 ms 2296 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 4 ms 760 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 4 ms 760 KB Output is correct
20 Correct 4 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 9 ms 2296 KB Output is correct
3 Correct 9 ms 2328 KB Output is correct
4 Correct 9 ms 2424 KB Output is correct
5 Correct 9 ms 2304 KB Output is correct
6 Correct 8 ms 2424 KB Output is correct
7 Correct 8 ms 2296 KB Output is correct
8 Correct 9 ms 2296 KB Output is correct
9 Correct 8 ms 2296 KB Output is correct
10 Correct 8 ms 2296 KB Output is correct
11 Correct 9 ms 2296 KB Output is correct
12 Correct 8 ms 2296 KB Output is correct
13 Correct 8 ms 2296 KB Output is correct
14 Correct 8 ms 2296 KB Output is correct
15 Correct 8 ms 2296 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 4 ms 760 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 4 ms 760 KB Output is correct
20 Correct 4 ms 760 KB Output is correct
21 Incorrect 237 ms 2168 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 9 ms 2296 KB Output is correct
3 Correct 9 ms 2328 KB Output is correct
4 Correct 9 ms 2424 KB Output is correct
5 Correct 9 ms 2304 KB Output is correct
6 Correct 8 ms 2424 KB Output is correct
7 Correct 8 ms 2296 KB Output is correct
8 Correct 9 ms 2296 KB Output is correct
9 Correct 8 ms 2296 KB Output is correct
10 Correct 8 ms 2296 KB Output is correct
11 Correct 9 ms 2296 KB Output is correct
12 Correct 8 ms 2296 KB Output is correct
13 Correct 8 ms 2296 KB Output is correct
14 Correct 8 ms 2296 KB Output is correct
15 Correct 8 ms 2296 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 4 ms 760 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 4 ms 760 KB Output is correct
20 Correct 4 ms 760 KB Output is correct
21 Incorrect 237 ms 2168 KB Output isn't correct
22 Halted 0 ms 0 KB -