답안 #415281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
415281 2021-05-31T19:40:49 Z errorgorn Skyscraper (JOI16_skyscraper) C++17
15 / 100
68 ms 130400 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;
int arr[105];
int 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;
	rep(x,0,n) cin>>arr[x];
	sort(arr,arr+n);
	
	rep(x,0,n) arr[x]=arr[x+1]-arr[x];
	//rep(x,0,n-1) cout<<arr[x]<<" "; cout<<endl;
	
	memset(memo,-1,sizeof(memo));
	cout<<dp(0,0,0,2)<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 130400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 130316 KB Output is correct
2 Correct 68 ms 130400 KB Output is correct
3 Correct 61 ms 130336 KB Output is correct
4 Correct 56 ms 130392 KB Output is correct
5 Correct 58 ms 130348 KB Output is correct
6 Correct 66 ms 130372 KB Output is correct
7 Correct 65 ms 130372 KB Output is correct
8 Correct 66 ms 130280 KB Output is correct
9 Correct 67 ms 130352 KB Output is correct
10 Correct 67 ms 130324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 130400 KB Output isn't correct
2 Halted 0 ms 0 KB -