Submission #41833

#TimeUsernameProblemLanguageResultExecution timeMemory
41833IvanCBoat (APIO16_boat)C++14
27 / 100
121 ms9232 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 101; const ll MOD = 1e9 + 7; ll dp[MAXN][2*MAXN][MAXN],dp2[MAXN][2*MAXN]; ll precalc[MAXN],A[MAXN],B[MAXN],N,M; vector<ll> intervalos; ll binary_expo(ll val,ll pot){ if(pot == 0) return 1LL; if(pot % 2 == 0){ ll davez = binary_expo(val,pot/2); return (davez*davez) % MOD; } return (val*binary_expo(val,pot-1)) % MOD; } int main(){ cin >> N; for(int i = 1;i<=N;i++){ cin >> A[i] >> B[i]; B[i]++; intervalos.push_back(A[i]); intervalos.push_back(B[i]); } sort(intervalos.begin(),intervalos.end()); intervalos.erase(unique(intervalos.begin(),intervalos.end()),intervalos.end()); M = intervalos.size() - 2; ll tot = 0; for(int v = M;v>=0;v--){ ll tam = intervalos[v+1] - intervalos[v]; ll vaiate = min(tam,N); for(ll i = 2;i<=vaiate;i++){ precalc[i] = (tam - i + 1)*binary_expo(i,MOD-2); precalc[i] %= MOD; } for(ll i = N;i>=1;i--){ if(!(A[i] <= intervalos[v] && intervalos[v+1] <= B[i] )) continue; dp[i][v][1] = 1; for(ll j = i+1;j<=N;j++){ for(ll u = v + 1;u<=M;u++){ dp[i][v][1] += dp2[j][u]; } } dp[i][v][1] %= MOD; dp[i][v][1] = (dp[i][v][1] * tam) % MOD; for(ll j = i + 1;j<=N;j++){ for(ll k = 2;k<=vaiate;k++){ dp[i][v][k] += dp[j][v][k-1]; } } dp2[i][v] = dp[i][v][1]; for(ll k = 2;k<=vaiate;k++){ dp[i][v][k] %= MOD; dp[i][v][k] *= precalc[k]; dp[i][v][k] %= MOD; dp2[i][v] += dp[i][v][k]; } dp2[i][v] %= MOD; tot += dp2[i][v]; tot %= MOD; } } cout << tot << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...