답안 #499781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499781 2021-12-29T12:33:50 Z Stickfish Boat (APIO16_boat) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const int MAXN = 502;

ll fact[MAXN * 2];
ll rfact[MAXN * 2];

ll pw(ll a, ll m) {
    if (!m)
        return 1;
    a %= MOD;
    if (m % 2)
        return (a * pw(a, m - 1)) % MOD;
    return pw(a * a, m / 2);
}

ll choose[MAXN * 2][MAXN];

ll dp[MAXN * 2][MAXN];
ll ndp[MAXN * 2][MAXN];

ll a[MAXN];
ll b[MAXN];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    rfact[0] = fact[0] = 1;
    for (int i = 1; i < 2 * MAXN; ++i) {
        fact[i] = (fact[i - 1] * i) % MOD;
        rfact[i] = pw(fact[i], MOD - 2);
    }
    int n;
    cin >> n;
    vector<ll> cpr = {0};
    vector<ll> sz;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        ++b[i];
        cpr.push_back(a[i]);
        cpr.push_back(b[i]);
    }
    sort(cpr.begin(), cpr.end());
    cpr.resize(unique(cpr.begin(), cpr.end()) - cpr.begin());
    int m = cpr.size();
    for (int i = 0; i + 1 < m; ++i) {
        sz.push_back(cpr[i + 1] - cpr[i]);
        choose[i][0] = 1;
        for (ll k = 1; k <= i && k <= sz[j]; ++k) {
            choose[i][k] = (choose[i][k - 1] * (i - k + 1)) % MOD;
            choose[i][k] = (choose[i][k] * pw(k, MOD - 2)) % MOD;
        }
    }
    //printf("\n");
    for (int i = 0; i < n; ++i) {
        a[i] = lower_bound(cpr.begin(), cpr.end(), a[i]) - cpr.begin();
        b[i] = lower_bound(cpr.begin(), cpr.end(), b[i]) - cpr.begin();
    } for (int i = 0; i < m; ++i)
        dp[i][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k <= n; ++k)
                ndp[j][k] = 0;
        }
        for (int j = b[i] - 1; j >= a[i]; --j) {
            for (ll k = 0; k <= sz[j] && k <= i + 1; ++k) {
                if (k)
                    ndp[j][k] += dp[j][k - 1];
                ndp[j][k] %= MOD;
                ndp[j + 1][0] += ndp[j][k] * choose[j][k];
                ndp[j + 1][0] %= MOD;
            }
        }
        for (int j = 1; j < m; ++j) {
            ndp[j][0] += ndp[j - 1][0];
            ndp[j][0] %= MOD;
        }
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k <= n; ++k) {
                ndp[j][k] += dp[j][k];
                ndp[j][k] %= MOD;
            }
        }
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k <= n; ++k)
                dp[j][k] = ndp[j][k];
        }
        //printf("---\n");
        //for (int j = 0; j < m; ++j) {
            //for (int k = 0; k <= n; ++k)
                //printf("%Ld ", dp[j][k]);
            //printf("\n");
        //}
    }
    cout << dp[m - 1][0] - 1 << endl;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:55:42: error: 'j' was not declared in this scope
   55 |         for (ll k = 1; k <= i && k <= sz[j]; ++k) {
      |                                          ^