Submission #877113

#TimeUsernameProblemLanguageResultExecution timeMemory
877113AMnuBoat (APIO16_boat)C++14
9 / 100
2028 ms6768 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e2+5, MOD = 1e9+7; int N, M, A[MAXN], B[MAXN], S[2*MAXN]; long long dp[2*MAXN][MAXN], pref[2*MAXN][MAXN], inv[MAXN]; long long comb(int x,int y) { long long ret = inv[y]; for (int i=0; i<y; i++) { ret = ret*(x-i)%MOD; } return ret; } int main() { cin >> N; for (int i=1; i<=N; i++) { cin >> A[i] >> B[i]; S[2*i-2] = A[i]; S[2*i-1] = B[i]+1; } sort(S,S+2*N); for (int i=1; i<2*N; i++) { if (S[i] != S[M]) { M++; S[M] = S[i]; } } inv[1] = 1; for (int i=2; i<=N; i++) { inv[i] = MOD - inv[N%i]*(N/i)%MOD; } for (int i=2; i<=N; i++) { inv[i] = inv[i-1]*inv[i]%MOD; } dp[0][0] = 1; for (int i=0; i<=N; i++) { pref[0][i] = 1; } for (int i=1; i<=M; i++) { pref[i][0] = 1; for (int j=1; j<=N; j++) { if (A[j]<=S[i-1] && S[i]-1<=B[j]) { dp[i][j] = comb(S[i]-S[i-1],1)*pref[i-1][j-1]%MOD; int cnt = 0; for (int k=j-1; k>=1; k--) { if (A[k]<=S[i-1] && S[i]<=B[k]) { for (int l=0; l<=cnt; l++) { dp[i][j] += comb(S[i]-S[i-1],l+2)*comb(cnt,l)%MOD * dp[i-1][k-1]; dp[i][j] %= MOD; } cnt++; } } } pref[i][j] = (dp[i][j] + pref[i][j-1] + pref[i-1][j] + MOD-pref[i-1][j-1]) % MOD; } } cout << (pref[M][N]+MOD-1) % MOD << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...