Submission #681959

# Submission time Handle Problem Language Result Execution time Memory
681959 2023-01-14T23:55:00 Z mahdi_hasnat Skyscraper (JOI16_skyscraper) C++17
15 / 100
57 ms 130408 KB
///****In the name of ALLAH, most Gracious, most Compassionate****//

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cerr<<endl

template < class T1,class T2>
ostream &operator <<(ostream &os,const pair < T1,T2 > &p)
{
    os<<"{"<<p.first<<","<<p.second<<"}";
    return os;
}
template <class T , size_t N>
ostream &operator <<(ostream &os,const array <T,N> &a)
{
	os<<"{";
	for(auto x: a)
		os<<x<<" ";
	os<<"}";
	return os;
}

template <class T>
ostream &operator <<(ostream &os,const vector<T> &a)
{
	os<<"{ ";
	for(auto x: a)
		os<<x<<" ";
	os<<"}";
	return os;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N=100+5;
const int M=1e3+5;
const ll oo=1e9+7;

int a[N];
int n,l;
int save[N][N][M][3];
int dp(int i,int cc,int sm,ll side)
{
	
	// DBG(i);
	// DBG(cc);
	// DBG(sm);
	// DBG(side);
	// DBG(side == 2 and cc == 1);
	// NL;
	assert(cc>=0);
	if(sm>l) return 0;
	if(i==n+1) return side == 2 and cc == 1;
	int &ret = save[i][cc][sm][side];
	if(ret!=-1) return ret;
	ret= 0;
	int d =a[i]-a[i-1];
	int nxt = sm + d* (2*cc-side);

	// new comp
	{
		ret = (ret + dp(i+1,cc+1,nxt,side)*1LL*(cc+1 - side))%oo;
	}

	// merge
	if(cc>=2)
	{
		ret =(ret + dp(i+1,cc-1,nxt,side) * 1LL * (cc-1))%oo;
	}
	// add
	if(2*cc-side>=1)
	{
		ret = (ret + dp(i+1,cc,nxt,side)* 1LL * (2*cc-side)	)%oo;
	}

	if(side <2)
	{
		ret = (ret +dp(i+1,cc+1,nxt,side +1 ) * (2-side))%oo;
		// if(cc==0)
		// 	ret = (ret +dp(i+1,cc+1,nxt,side +2 ) * (1))%oo;

		ret = (ret +dp(i+1,cc,nxt,side +1 ) * (2-side))%oo;
	}


	return ret;
}


int32_t main()
{
    FastIO;
	cin>>n>>l;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	if(n==1)
	{
		cout<<"1\n";
		return 0;
	}
	// a[0]=a[1];
	// DBG(a);
	// for(int i=1;i<=n;i++) cerr<<a[i]<<" ";
	// NL;

	// for(int i=1;i<=n;i++)
	// {
	// 	DBG(i);
	// 	DBG(dp(i,0,0,0));
	// 	NL;
	// }
	memset(save,-1,sizeof save);
	cout<<dp(1,0,0,0)<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 45 ms 130388 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 130324 KB Output is correct
2 Correct 46 ms 130328 KB Output is correct
3 Correct 47 ms 130320 KB Output is correct
4 Correct 46 ms 130380 KB Output is correct
5 Correct 53 ms 130296 KB Output is correct
6 Correct 57 ms 130300 KB Output is correct
7 Correct 51 ms 130364 KB Output is correct
8 Correct 47 ms 130356 KB Output is correct
9 Correct 49 ms 130396 KB Output is correct
10 Correct 49 ms 130408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 45 ms 130388 KB Output isn't correct
3 Halted 0 ms 0 KB -