# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
42613 | 2018-03-01T12:53:24 Z | fefe | Boat (APIO16_boat) | C++14 | 183 ms | 15336 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[3*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+MOD)%MOD); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 12152 KB | Output is correct |
2 | Correct | 20 ms | 12384 KB | Output is correct |
3 | Correct | 20 ms | 12384 KB | Output is correct |
4 | Correct | 20 ms | 12460 KB | Output is correct |
5 | Correct | 20 ms | 12652 KB | Output is correct |
6 | Correct | 20 ms | 12656 KB | Output is correct |
7 | Correct | 22 ms | 12684 KB | Output is correct |
8 | Correct | 21 ms | 12700 KB | Output is correct |
9 | Correct | 21 ms | 12832 KB | Output is correct |
10 | Correct | 20 ms | 12832 KB | Output is correct |
11 | Correct | 20 ms | 12832 KB | Output is correct |
12 | Correct | 21 ms | 12832 KB | Output is correct |
13 | Correct | 23 ms | 12832 KB | Output is correct |
14 | Correct | 20 ms | 12956 KB | Output is correct |
15 | Correct | 23 ms | 12972 KB | Output is correct |
16 | Correct | 20 ms | 12972 KB | Output is correct |
17 | Correct | 20 ms | 12972 KB | Output is correct |
18 | Correct | 20 ms | 12972 KB | Output is correct |
19 | Correct | 20 ms | 12972 KB | Output is correct |
20 | Correct | 22 ms | 12972 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 12152 KB | Output is correct |
2 | Correct | 20 ms | 12384 KB | Output is correct |
3 | Correct | 20 ms | 12384 KB | Output is correct |
4 | Correct | 20 ms | 12460 KB | Output is correct |
5 | Correct | 20 ms | 12652 KB | Output is correct |
6 | Correct | 20 ms | 12656 KB | Output is correct |
7 | Correct | 22 ms | 12684 KB | Output is correct |
8 | Correct | 21 ms | 12700 KB | Output is correct |
9 | Correct | 21 ms | 12832 KB | Output is correct |
10 | Correct | 20 ms | 12832 KB | Output is correct |
11 | Correct | 20 ms | 12832 KB | Output is correct |
12 | Correct | 21 ms | 12832 KB | Output is correct |
13 | Correct | 23 ms | 12832 KB | Output is correct |
14 | Correct | 20 ms | 12956 KB | Output is correct |
15 | Correct | 23 ms | 12972 KB | Output is correct |
16 | Correct | 20 ms | 12972 KB | Output is correct |
17 | Correct | 20 ms | 12972 KB | Output is correct |
18 | Correct | 20 ms | 12972 KB | Output is correct |
19 | Correct | 20 ms | 12972 KB | Output is correct |
20 | Correct | 22 ms | 12972 KB | Output is correct |
21 | Incorrect | 183 ms | 15336 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 15336 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 12152 KB | Output is correct |
2 | Correct | 20 ms | 12384 KB | Output is correct |
3 | Correct | 20 ms | 12384 KB | Output is correct |
4 | Correct | 20 ms | 12460 KB | Output is correct |
5 | Correct | 20 ms | 12652 KB | Output is correct |
6 | Correct | 20 ms | 12656 KB | Output is correct |
7 | Correct | 22 ms | 12684 KB | Output is correct |
8 | Correct | 21 ms | 12700 KB | Output is correct |
9 | Correct | 21 ms | 12832 KB | Output is correct |
10 | Correct | 20 ms | 12832 KB | Output is correct |
11 | Correct | 20 ms | 12832 KB | Output is correct |
12 | Correct | 21 ms | 12832 KB | Output is correct |
13 | Correct | 23 ms | 12832 KB | Output is correct |
14 | Correct | 20 ms | 12956 KB | Output is correct |
15 | Correct | 23 ms | 12972 KB | Output is correct |
16 | Correct | 20 ms | 12972 KB | Output is correct |
17 | Correct | 20 ms | 12972 KB | Output is correct |
18 | Correct | 20 ms | 12972 KB | Output is correct |
19 | Correct | 20 ms | 12972 KB | Output is correct |
20 | Correct | 22 ms | 12972 KB | Output is correct |
21 | Incorrect | 183 ms | 15336 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |