Submission #415286

# Submission time Handle Problem Language Result Execution time Memory
415286 2021-05-31T19:53:36 Z errorgorn Skyscraper (JOI16_skyscraper) C++17
100 / 100
197 ms 260548 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

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

const int MOD=1000000007;

int n,m;
ll arr[105];
ll memo[105][105][1005][3];

ll dp(ll i,ll j,ll k,ll l){
	//processed, num connected, cost, sides
	if (k>m) return 0;
	if (i==n){
		if (j==1 && l==0) return 1;
		else return 0;
	}
	if (memo[i][j][k][l]!=-1) return memo[i][j][k][l];
	
	ll res=0;
	
	//put on a endpoint and touch connected
	if (l && j){
		res=(res+dp(i+1,j,k+(2*j-2+(l-1))*arr[i],l-1)*l)%MOD;
	}
	
	//put on endpoint and dont touch
	if (l){
		res=(res+dp(i+1,j+1,k+(2*j+(l-1))*arr[i],l-1)*l)%MOD;
	}
	
	//touch connected
	if (j){
		res=(res+dp(i+1,j,k+(2*j-2+l)*arr[i],l)*(2*(j-1)+l))%MOD;
	}
	
	//touch nothing
	res=(res+dp(i+1,j+1,k+(2*j+l)*arr[i],l)*(j-1+l))%MOD;
	
	//join 2 connected
	if (j>1){
		res=(res+dp(i+1,j-1,k+(2*j-4+l)*arr[i],l)*(j-1))%MOD;
	}
	
	//cout<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<res<<endl;
	return memo[i][j][k][l]=res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>m;
	if (n==1){
		cout<<1<<endl;
		return 0;
	}
	
	rep(x,0,n) cin>>arr[x];
	sort(arr,arr+n);
	
	rep(x,0,n) arr[x]=arr[x+1]-arr[x];
	
	memset(memo,-1,sizeof(memo));
	cout<<dp(0,0,0,2)<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 111 ms 260488 KB Output is correct
3 Correct 121 ms 260384 KB Output is correct
4 Correct 121 ms 260424 KB Output is correct
5 Correct 121 ms 260476 KB Output is correct
6 Correct 121 ms 260428 KB Output is correct
7 Correct 123 ms 260496 KB Output is correct
8 Correct 119 ms 260420 KB Output is correct
9 Correct 122 ms 260432 KB Output is correct
10 Correct 121 ms 260468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 260420 KB Output is correct
2 Correct 124 ms 260468 KB Output is correct
3 Correct 109 ms 260484 KB Output is correct
4 Correct 128 ms 260412 KB Output is correct
5 Correct 121 ms 260456 KB Output is correct
6 Correct 108 ms 260420 KB Output is correct
7 Correct 118 ms 260428 KB Output is correct
8 Correct 111 ms 260416 KB Output is correct
9 Correct 141 ms 260480 KB Output is correct
10 Correct 126 ms 260460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 111 ms 260488 KB Output is correct
3 Correct 121 ms 260384 KB Output is correct
4 Correct 121 ms 260424 KB Output is correct
5 Correct 121 ms 260476 KB Output is correct
6 Correct 121 ms 260428 KB Output is correct
7 Correct 123 ms 260496 KB Output is correct
8 Correct 119 ms 260420 KB Output is correct
9 Correct 122 ms 260432 KB Output is correct
10 Correct 121 ms 260468 KB Output is correct
11 Correct 109 ms 260420 KB Output is correct
12 Correct 124 ms 260468 KB Output is correct
13 Correct 109 ms 260484 KB Output is correct
14 Correct 128 ms 260412 KB Output is correct
15 Correct 121 ms 260456 KB Output is correct
16 Correct 108 ms 260420 KB Output is correct
17 Correct 118 ms 260428 KB Output is correct
18 Correct 111 ms 260416 KB Output is correct
19 Correct 141 ms 260480 KB Output is correct
20 Correct 126 ms 260460 KB Output is correct
21 Correct 122 ms 260544 KB Output is correct
22 Correct 196 ms 260420 KB Output is correct
23 Correct 166 ms 260436 KB Output is correct
24 Correct 197 ms 260488 KB Output is correct
25 Correct 185 ms 260548 KB Output is correct
26 Correct 159 ms 260504 KB Output is correct
27 Correct 126 ms 260440 KB Output is correct
28 Correct 141 ms 260468 KB Output is correct
29 Correct 186 ms 260388 KB Output is correct
30 Correct 172 ms 260452 KB Output is correct