# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
400058 | juggernaut | Boat (APIO16_boat) | C++17 | 1444 ms | 4296 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
#define printl(args...)printf(args)
#else
#define printl(args...)
#endif
#define mod 1000000007
vector<int>aux;
array<int,2>v[505];
ll dp[1005][505],inv[505];
int main(){
int n,i,j,e;
scanf("%d",&n);
aux={-1};
inv[1]=1;
for(i=2;i<=n;i++)
inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(i=1;i<=n;i++){
scanf("%d%d",&v[i][0],&v[i][1]);
++v[i][1];
aux.push_back(v[i][0]);
aux.push_back(v[i][1]);
}
sort(aux.begin(),aux.end());
aux.resize(unique(aux.begin(),aux.end())-aux.begin());
int m=aux.size();
for(i=0;i<m;i++)
dp[i][0]=1;
for(i=1;i<=n;i++){
for(j=m-1;j>=1;j--)
if (v[i][0]<=aux[j-1] && aux[j]<=v[i][1]){
int cnt=aux[j]-aux[j-1];
for(e=min(cnt,i);e>=1;e--)
dp[j][e]=(dp[j][e]+dp[j][e-1]*(cnt-e+1)%mod*inv[e])%mod;
}
for(j=1;j<=m;j++){
dp[j][0]=0;
for(e=0;e<=n;e++)
dp[j][0]=(dp[j][0]+dp[j-1][e])%mod;
}
}
printf("%lld\n",(dp[m][0]+mod-1)%mod);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |