# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42609 | 2018-03-01T11:42:14 Z | fefe | Boat (APIO16_boat) | C++14 | 2 ms | 376 KB |
#include<bits/stdc++.h> #define MAX_N 505 #define MOD 1000000007LL #define pb push_back typedef long long LL; using namespace std; struct node{ LL s,e; }arr[MAX_N]; LL n,ans,inv[MAX_N]; LL t[MAX_N][5*MAX_N],sum[MAX_N][5*MAX_N]; vector<LL> X; LL Pow(LL x,LL y){ if(y==0) return 1; if(y==1) return x; LL z=pow(x,y/2); z*=z;z%=MOD; if(y%2) z*=x; z%=MOD; return z; } int main(){ LL i,j,k,s,e,x,y,S,E,cnt; scanf("%lld",&n); for(i=1;i<=n;i++){ scanf("%lld %lld",&arr[i].s,&arr[i].e); X.pb(arr[i].s);X.pb(arr[i].e); } for(i=1;i<=1000;i++) inv[i]=Pow(i,MOD-2); sort(X.begin(),X.end());X.erase(unique(X.begin(),X.end()),X.end()); t[0][0]=sum[0][0]=1; for(i=1;i<=4*n+1;i++) sum[0][i]=1; for(i=1;i<=n;i++){ S=lower_bound(X.begin(),X.end(),arr[i].s)-X.begin(); E=lower_bound(X.begin(),X.end(),arr[i].e)-X.begin(); for(j=2*S+1;j<=2*E+1;j++){ s=j%2?X[j/2]:X[j/2-1]+1; e=j%2?X[j/2]:X[j/2]-1; if(s>e) continue; cnt=1; x=1; t[i][j]=(sum[i-1][j-1]*(e-s+1))%MOD; if(e==s) continue; for(k=i-1;k>=1;k--){ if(arr[k].s>s || arr[k].e<e) continue; cnt++; x*=(e-s-1+cnt);x%=MOD;x*=inv[cnt];x%=MOD; t[i][j]=(t[i][j]+sum[k-1][j-1]*x)%MOD; } } sum[i][0]=sum[i-1][0]; for(j=1;j<=4*n+1;j++){ sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+t[i][j]+MOD)%MOD; } } printf("%lld\n",sum[n][4*n+1]-1); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |