Submission #202274

# Submission time Handle Problem Language Result Execution time Memory
202274 2020-02-15T03:42:14 Z Segtree Skyscraper (JOI16_skyscraper) C++14
100 / 100
914 ms 318712 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
ll n,L,a[110];
ll dp[110][2][2][110][1010];
ll dq[110][2][2][110];

void ad(ll i,ll l,ll r,ll c,ll cost,ll val){
    ll id=cost-dq[i][l][r][c];
    if(id<L){
	mad(dp[i][l][r][c][id],val);
    }
}
int main(){
    cin>>n>>L;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    
    if(n==1){
	cout<<1<<endl;
	return 0;
    }
    
    rep(i,n)rep(l,2)rep(r,2)rep(c,n)dq[i][l][r][c]=1e17;
    dq[0][0][0][1]=-2*a[0];
    dq[0][0][1][1]=-1*a[0];
    dq[0][1][0][1]=-1*a[0];
    rep(i,n-1)rep(l,2)rep(r,2)rep(c,n){
	if(l==1&&r==1&&c==1)continue;
	ll cost=dq[i][l][r][c];
	if(c+1>=1)chmin(dq[i+1][l][r][c+1],cost-2*a[i+1]);
	if(c+0>=1)chmin(dq[i+1][l][r][c+0],cost);
	if(c-1>=1)chmin(dq[i+1][l][r][c-1],cost+2*a[i+1]);
	if(l==0){
	    if(c+1>=1)chmin(dq[i+1][1][r][c+1],cost-a[i+1]);
	    if(c+0>=1)chmin(dq[i+1][1][r][c+0],cost+a[i+1]);
	}
	if(r==0){
	    if(c+1>=1)chmin(dq[i+1][l][1][c+1],cost-a[i+1]);
	    if(c+0>=1)chmin(dq[i+1][l][1][c+0],cost+a[i+1]);
	}
    }
    
    rep(i,n)rep(l,2)rep(r,2)rep(c,n)rep(cost,L)dp[i][l][r][c][cost]=0;
    dp[0][0][0][1][-2*a[0]-dq[0][0][0][1]]=1;
    dp[0][0][1][1][-1*a[0]-dq[0][0][1][1]]=1;
    dp[0][1][0][1][-1*a[0]-dq[0][1][0][1]]=1;
    rep(i,n-1)rep(l,2)rep(r,2)rep(c,n)rep(cosyo,L){
	if(l==1&&r==1&&c==1)continue;
	ll cost=dq[i][l][r][c]+cosyo;
	ll val=dp[i][l][r][c][cosyo];
	if(c+1>=1)ad(i+1,l,r,c+1,cost-2*a[i+1],val*(c+1-l-r));
	if(c+0>=1)ad(i+1,l,r,c+0,cost,val*(c*2-l-r));
	if(c-1>=1)ad(i+1,l,r,c-1,cost+2*a[i+1],val*(c-1));
	if(l==0){
	    if(c+1>=1)ad(i+1,1,r,c+1,cost-a[i+1],val);
	    if(c+0>=1)ad(i+1,1,r,c+0,cost+a[i+1],val);
	}
	if(r==0){
	    if(c+1>=1)ad(i+1,l,1,c+1,cost-a[i+1],val);
	    if(c+0>=1)ad(i+1,l,1,c+0,cost+a[i+1],val);
	}
    }
    ll ans=0;
    rep(cosyo,L){
	ll cost=dq[n-1][1][1][1]+cosyo;
	if(cost<=L)mad(ans,dp[n-1][1][1][1][cosyo]);
    }
    cout<<ans<<endl;
}


# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 6 ms 1016 KB Output is correct
5 Correct 9 ms 2428 KB Output is correct
6 Correct 9 ms 2424 KB Output is correct
7 Correct 6 ms 1528 KB Output is correct
8 Correct 6 ms 1532 KB Output is correct
9 Correct 9 ms 2552 KB Output is correct
10 Correct 6 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3448 KB Output is correct
2 Correct 9 ms 4856 KB Output is correct
3 Correct 7 ms 4216 KB Output is correct
4 Correct 8 ms 4856 KB Output is correct
5 Correct 9 ms 4860 KB Output is correct
6 Correct 9 ms 4728 KB Output is correct
7 Correct 7 ms 3960 KB Output is correct
8 Correct 7 ms 4216 KB Output is correct
9 Correct 8 ms 4600 KB Output is correct
10 Correct 8 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 6 ms 1016 KB Output is correct
5 Correct 9 ms 2428 KB Output is correct
6 Correct 9 ms 2424 KB Output is correct
7 Correct 6 ms 1528 KB Output is correct
8 Correct 6 ms 1532 KB Output is correct
9 Correct 9 ms 2552 KB Output is correct
10 Correct 6 ms 1528 KB Output is correct
11 Correct 7 ms 3448 KB Output is correct
12 Correct 9 ms 4856 KB Output is correct
13 Correct 7 ms 4216 KB Output is correct
14 Correct 8 ms 4856 KB Output is correct
15 Correct 9 ms 4860 KB Output is correct
16 Correct 9 ms 4728 KB Output is correct
17 Correct 7 ms 3960 KB Output is correct
18 Correct 7 ms 4216 KB Output is correct
19 Correct 8 ms 4600 KB Output is correct
20 Correct 8 ms 4728 KB Output is correct
21 Correct 28 ms 28152 KB Output is correct
22 Correct 729 ms 193976 KB Output is correct
23 Correct 914 ms 318628 KB Output is correct
24 Correct 802 ms 317816 KB Output is correct
25 Correct 876 ms 318584 KB Output is correct
26 Correct 787 ms 318200 KB Output is correct
27 Correct 367 ms 237208 KB Output is correct
28 Correct 444 ms 254456 KB Output is correct
29 Correct 732 ms 317280 KB Output is correct
30 Correct 884 ms 318712 KB Output is correct