Submission #406641

# Submission time Handle Problem Language Result Execution time Memory
406641 2021-05-17T22:53:58 Z gevacrt Boat (APIO16_boat) C++17
36 / 100
2000 ms 4420 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define int ll

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

int binexp(int base, int pow, int M=MOD){
    int res = 1;
    while(pow){
        if(pow & 1) res *= base;
        pow >>= 1, base *= base;
        if(M) base %= M, res %= M;
    }
    return res;
}

vi fac(5e2+10), inv_fac(5e2+10);

int nCk(int n, int k){
    if(n-k < k) k = n-k;

    int v = inv_fac[k];
    while(k--){
        v *= n; v %= MOD;
        n--;
    }
    return v;
}

vii A; vi B; vvi dp;

int solve(int n, int c){
    if(n == -1) return 1;
    if(c == 0) return 1;
    if(dp[n][c] != -1)
        return dp[n][c];

    auto &v = dp[n][c]; v = solve(n, c-1);

    for(int x = n, cnt = 0; x >= 0; x--){
        if(!(A[x].first <= B[c-1] and B[c] <= A[x].second))
            continue;
    
        for(int k = 0; k <= min(cnt, B[c]-B[c-1]-1); k++){
            int val = nCk(B[c]-B[c-1], k+1)*nCk(cnt, k); val %= MOD;
            val *= solve(x-1, c-1), val %= MOD;
            v += val; v %= MOD;
        }

        cnt++;
    }

    return v;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    fac[0] = inv_fac[0] = 1;
    for(int x = 1; x <= 5e2; x++)
        fac[x] = (x*fac[x-1])%MOD,
        inv_fac[x] = binexp(fac[x], MOD-2);

    int N; cin >> N;

    A.resize(N);
    for(auto &[l, r] : A){
        cin >> l >> r; r++;    
        B.push_back(l); B.push_back(r);
    }

    sort(all(B));

    dp.resize(N, vi(B.size(), -1));
    cout << solve(N-1, B.size()-1)-1 << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 167 ms 4420 KB Output is correct
2 Correct 164 ms 4372 KB Output is correct
3 Correct 164 ms 4380 KB Output is correct
4 Correct 154 ms 4376 KB Output is correct
5 Correct 160 ms 4372 KB Output is correct
6 Correct 150 ms 4368 KB Output is correct
7 Correct 143 ms 4372 KB Output is correct
8 Correct 187 ms 4300 KB Output is correct
9 Correct 172 ms 4364 KB Output is correct
10 Correct 150 ms 4300 KB Output is correct
11 Correct 146 ms 4300 KB Output is correct
12 Correct 148 ms 4364 KB Output is correct
13 Correct 145 ms 4368 KB Output is correct
14 Correct 144 ms 4380 KB Output is correct
15 Correct 149 ms 4368 KB Output is correct
16 Correct 186 ms 4364 KB Output is correct
17 Correct 166 ms 4372 KB Output is correct
18 Correct 175 ms 4420 KB Output is correct
19 Correct 164 ms 4372 KB Output is correct
20 Correct 173 ms 4420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 4420 KB Output is correct
2 Correct 164 ms 4372 KB Output is correct
3 Correct 164 ms 4380 KB Output is correct
4 Correct 154 ms 4376 KB Output is correct
5 Correct 160 ms 4372 KB Output is correct
6 Correct 150 ms 4368 KB Output is correct
7 Correct 143 ms 4372 KB Output is correct
8 Correct 187 ms 4300 KB Output is correct
9 Correct 172 ms 4364 KB Output is correct
10 Correct 150 ms 4300 KB Output is correct
11 Correct 146 ms 4300 KB Output is correct
12 Correct 148 ms 4364 KB Output is correct
13 Correct 145 ms 4368 KB Output is correct
14 Correct 144 ms 4380 KB Output is correct
15 Correct 149 ms 4368 KB Output is correct
16 Correct 186 ms 4364 KB Output is correct
17 Correct 166 ms 4372 KB Output is correct
18 Correct 175 ms 4420 KB Output is correct
19 Correct 164 ms 4372 KB Output is correct
20 Correct 173 ms 4420 KB Output is correct
21 Execution timed out 2083 ms 4300 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 480 KB Output is correct
2 Correct 128 ms 492 KB Output is correct
3 Correct 245 ms 484 KB Output is correct
4 Correct 262 ms 460 KB Output is correct
5 Correct 325 ms 584 KB Output is correct
6 Correct 1815 ms 484 KB Output is correct
7 Correct 1800 ms 492 KB Output is correct
8 Correct 1790 ms 484 KB Output is correct
9 Correct 1794 ms 484 KB Output is correct
10 Correct 1835 ms 488 KB Output is correct
11 Correct 571 ms 460 KB Output is correct
12 Correct 364 ms 580 KB Output is correct
13 Correct 518 ms 496 KB Output is correct
14 Correct 501 ms 488 KB Output is correct
15 Correct 600 ms 484 KB Output is correct
16 Correct 165 ms 460 KB Output is correct
17 Correct 127 ms 488 KB Output is correct
18 Correct 132 ms 460 KB Output is correct
19 Correct 100 ms 460 KB Output is correct
20 Correct 156 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 4420 KB Output is correct
2 Correct 164 ms 4372 KB Output is correct
3 Correct 164 ms 4380 KB Output is correct
4 Correct 154 ms 4376 KB Output is correct
5 Correct 160 ms 4372 KB Output is correct
6 Correct 150 ms 4368 KB Output is correct
7 Correct 143 ms 4372 KB Output is correct
8 Correct 187 ms 4300 KB Output is correct
9 Correct 172 ms 4364 KB Output is correct
10 Correct 150 ms 4300 KB Output is correct
11 Correct 146 ms 4300 KB Output is correct
12 Correct 148 ms 4364 KB Output is correct
13 Correct 145 ms 4368 KB Output is correct
14 Correct 144 ms 4380 KB Output is correct
15 Correct 149 ms 4368 KB Output is correct
16 Correct 186 ms 4364 KB Output is correct
17 Correct 166 ms 4372 KB Output is correct
18 Correct 175 ms 4420 KB Output is correct
19 Correct 164 ms 4372 KB Output is correct
20 Correct 173 ms 4420 KB Output is correct
21 Execution timed out 2083 ms 4300 KB Time limit exceeded
22 Halted 0 ms 0 KB -