Submission #399993

#TimeUsernameProblemLanguageResultExecution timeMemory
399993jeqchoBoat (APIO16_boat)C++17
9 / 100
22 ms4356 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define fi first #define se second // subtask 1 and 2 int const N=5e2+3; ll a[N],b[N]; ll dp[N][2*N]; ll mod =1e9+7; ll aps(ll n, ll d) { return (n*(2+(n-1)*d) / 2)%mod; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; set<ll> st; F0R(i,n) { cin>>a[i]>>b[i]; --a[i]; st.insert(a[i]); st.insert(b[i]); } st.insert(0); vi v(all(st)); map<ll,ll>mp; F0R(i,sz(st)) { mp[v[i]]=i; } F0R(i,n) { a[i]=mp[a[i]]; b[i]=mp[b[i]]; } F0R(j,sz(st)+1) { dp[0][j]=1; } dp[0][0]=0; F0R(i,n) { F0R(j,sz(st)) { dp[i+1][j+1]=dp[i][j+1]-dp[i][j]; dp[i+1][j+1]+=mod; dp[i+1][j+1]%=mod; } FOR(j,a[i]+1,b[i]+1) { ll l = v[j]-v[j-1]; F0R(k,l) { if(i-k<0)break; ll add = aps(l-k,k) * dp[i-k][j]; add%=mod; dp[i+1][j+1]+=add; dp[i+1][j+1]%=mod; } } F0R(j,sz(st)) { dp[i+1][j+1]+=dp[i+1][j]; dp[i+1][j+1]%=mod; } } ll ans=dp[n][sz(st)]-1; ans+=mod; ans%=mod; cout<<ans<<'\n'; 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...