답안 #199305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199305 2020-01-30T23:06:37 Z osaaateiasavtnl Boat (APIO16_boat) C++14
0 / 100
932 ms 8312 KB
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1007, MOD = 1000 * 1000 * 1000 + 7;
int fp(int a, int p) {
    ll ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = ans * c % MOD;
        c = c * c % MOD;
    }   
    return ans;
}   
int f[N], inv[N];
int n, l[N], r[N], dp[N][N], mem[N][N], cur[N], lmao[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    f[0] = inv[0] = 1;
    for (int i = 1; i < N; ++i) {
        f[i] = ((ll)f[i - 1] * i) % MOD;
        inv[i] = fp(f[i], MOD - 2);
    }   
    for (int i = 0; i < N; ++i)
        mem[i][0] = 1;
    for (int i = 1; i < N; ++i)
        for (int j = 1; j < N; ++j)
            mem[i][j] = (mem[i - 1][j] + mem[i - 1][j - 1]) % MOD;
    cin >> n;
    vector <int> c;
    for (int i = 1; i <= n; ++i) {
        cin >> l[i] >> r[i];
        c.app(l[i]); c.app(r[i] + 1);
    }                                
    sort(all(c));
    c.resize(unique(all(c)) - c.begin());

    dp[0][0] = 1;
    for (int i = 0; i + 1 < (int)c.size(); ++i) {   
        cur[0] = 1;
        ll t = 1;
        for (int j = 1; j <= n; ++j) {
            t = t * (c[i + 1] - c[i] - j + 1) % MOD;
            cur[j] = t * inv[j] % MOD;  
        }
        for (int mx = 1; mx <= n; ++mx) {
            lmao[mx] = 0;
            for (int cnt = 1; cnt <= mx; ++cnt)
                lmao[mx] = (lmao[mx] + (ll)mem[mx - 1][cnt - 1] * cur[cnt]) % MOD;
        }
        for (int j = 0; j <= n; ++j) {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
            int mx = 0;
            for (int k = j + 1; k <= n; ++k) {
                if (l[k] <= c[i] && c[i + 1] - 1 <= r[k]) {
                    ++mx;
                    dp[i + 1][k] = (dp[i + 1][k] + (ll)dp[i][j] * lmao[mx]) % MOD;
                }   
            }
        }   
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans += dp[c.size() - 1][i];
    cout << ans % MOD << '\n';
}   
# 결과 실행 시간 메모리 Grader output
1 Incorrect 932 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 932 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 5112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 932 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -