Submission #31362

# Submission time Handle Problem Language Result Execution time Memory
31362 2017-08-20T11:24:05 Z tatatan Skyscraper (JOI16_skyscraper) C++11
100 / 100
693 ms 174612 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;

int n,L,dp[105][105][2][2][1001],a[105],mod=1e9+7;

void add(int &x,LL y) {

	y%=mod;
	x+=y;
	if(x>=mod)
		x-=mod;

}

int f(int x,int cnt,int l,int r,int sum) {

	if(x>0)
		sum+=(cnt*2+l+r)*(a[x]-a[x-1]);
	if(sum>L||cnt<0)
		return 0;
	if(x==n-1)
		return (cnt==0);
	int &ret=dp[x][cnt][l][r][sum];
	if(ret!=-1)
		return ret;
	ret=0;
	add(ret,f(x+1,cnt,1,r,sum));
	add(ret,1LL*f(x+1,cnt-1,1,r,sum)*cnt);
	add(ret,f(x+1,cnt,l,1,sum));
	add(ret,1LL*f(x+1,cnt-1,l,1,sum)*cnt);
	add(ret,f(x+1,cnt+1,l,r,sum));
	add(ret,1LL*f(x+1,cnt,l,r,sum)*cnt*2);
	add(ret,1LL*f(x+1,cnt-1,l,r,sum)*cnt*(cnt-1));
	return ret;

}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	memset(dp,-1,sizeof dp);
	cin>>n>>L;
	for(int i=0;i<n;++i)
		cin>>a[i];
	sort(a,a+n);
	cout<<f(0,0,0,0,0)<< endl;

}	
# Verdict Execution time Memory Grader output
1 Correct 9 ms 174612 KB Output is correct
2 Correct 13 ms 174612 KB Output is correct
3 Correct 6 ms 174612 KB Output is correct
4 Correct 16 ms 174612 KB Output is correct
5 Correct 13 ms 174612 KB Output is correct
6 Correct 0 ms 174612 KB Output is correct
7 Correct 6 ms 174612 KB Output is correct
8 Correct 13 ms 174612 KB Output is correct
9 Correct 9 ms 174612 KB Output is correct
10 Correct 3 ms 174612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 174612 KB Output is correct
2 Correct 6 ms 174612 KB Output is correct
3 Correct 6 ms 174612 KB Output is correct
4 Correct 9 ms 174612 KB Output is correct
5 Correct 9 ms 174612 KB Output is correct
6 Correct 9 ms 174612 KB Output is correct
7 Correct 13 ms 174612 KB Output is correct
8 Correct 16 ms 174612 KB Output is correct
9 Correct 9 ms 174612 KB Output is correct
10 Correct 6 ms 174612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 174612 KB Output is correct
2 Correct 13 ms 174612 KB Output is correct
3 Correct 6 ms 174612 KB Output is correct
4 Correct 16 ms 174612 KB Output is correct
5 Correct 13 ms 174612 KB Output is correct
6 Correct 0 ms 174612 KB Output is correct
7 Correct 6 ms 174612 KB Output is correct
8 Correct 13 ms 174612 KB Output is correct
9 Correct 9 ms 174612 KB Output is correct
10 Correct 3 ms 174612 KB Output is correct
11 Correct 23 ms 174612 KB Output is correct
12 Correct 6 ms 174612 KB Output is correct
13 Correct 6 ms 174612 KB Output is correct
14 Correct 9 ms 174612 KB Output is correct
15 Correct 9 ms 174612 KB Output is correct
16 Correct 9 ms 174612 KB Output is correct
17 Correct 13 ms 174612 KB Output is correct
18 Correct 16 ms 174612 KB Output is correct
19 Correct 9 ms 174612 KB Output is correct
20 Correct 6 ms 174612 KB Output is correct
21 Correct 6 ms 174612 KB Output is correct
22 Correct 693 ms 174612 KB Output is correct
23 Correct 509 ms 174612 KB Output is correct
24 Correct 436 ms 174612 KB Output is correct
25 Correct 459 ms 174612 KB Output is correct
26 Correct 446 ms 174612 KB Output is correct
27 Correct 176 ms 174612 KB Output is correct
28 Correct 226 ms 174612 KB Output is correct
29 Correct 493 ms 174612 KB Output is correct
30 Correct 596 ms 174612 KB Output is correct