Submission #1188576

#TimeUsernameProblemLanguageResultExecution timeMemory
1188576MalixBoat (APIO16_boat)C++20
36 / 100
2095 ms8264 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef pair<int,int> pi; typedef vector<pi> pii; typedef tuple<ll,ll,ll> ti; typedef vector<ll> li; typedef vector<li> lii; #define REP(i,a,b) for(int i=a;i<b;i++) #define F first #define S second #define PB push_back #define LSOne(s) ((s)&(-s)) ll INF=1000000000000000010; int inf=1e9+10; ll M=1e9+7; ll md(ll x){ ll b=M-2; ll ans=1; while(b){ if(b&1){ ans*=x; ans%=M; } b/=2; x=(x*x)%M; } return ans; } int main() { // ios::sync_with_stdio(0); // cin.tie(0); int n;cin>>n; vector<pair<ll,ll>> a(n); set<ll> tmp; vector<ll> arr; REP(i,0,n){ cin>>a[i].F>>a[i].S; a[i].S++; tmp.insert(a[i].F); tmp.insert(a[i].S); } for(auto u:tmp)arr.PB(u); sort(arr.begin(),arr.end()); arr.back(); int m=arr.size(); vector<vector<ll>> dp(n,vector<ll>(m,0)),sm(n,vector<ll>(m,0)); vector<pair<int,int>> b(n); REP(i,0,n){ b[i].F=lower_bound(arr.begin(),arr.end(),a[i].F)-arr.begin(); b[i].S=lower_bound(arr.begin(),arr.end(),a[i].S)-arr.begin(); } REP(i,0,n){ REP(j,b[i].F,b[i].S){ dp[i][j]=arr[j+1]-arr[j]; sm[i][j]=1; if(j!=0)REP(k,0,i){ sm[i][j]+=dp[k][j-1]; sm[i][j]%=M; dp[i][j]+=dp[k][j-1]*(arr[j+1]-arr[j]); dp[i][j]%=M; } ll N=arr[j+1]-arr[j]-1; ll K=1; ll tot=N; for(int k=i-1;k>=0;k--){ if(sm[k][j]==0)continue; N++;K++; tot*=N; tot%=M; tot*=md(K); tot%=M; dp[i][j]+=tot*sm[k][j]; dp[i][j]%=M; } } REP(j,1,m)dp[i][j]+=dp[i][j-1]; } ll ans=0; REP(i,0,n){ ans+=dp[i][m-1]; ans%=M; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...