답안 #728593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728593 2023-04-22T16:35:28 Z vjudge1 Skyscraper (JOI16_skyscraper) C++17
100 / 100
523 ms 260560 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const ll MOD=1e9+7;
ll N,M,a[105],dp[105][105][1005][3];
int main(){
	cin>>N>>M;
	for(int i=1;i<=N;i++){
		cin>>a[i];
	}
	if(N==1){
		cout<<1<<endl;
		return 0;
	}
	sort(a+1,a+N+1);
	a[0]=0;
	memset(dp,0,sizeof(dp));
	dp[0][0][0][0]=1;
	for(int i=0;i<=N-1;i++){
		for(int cc=0;cc<=N-1;cc++){
			for(int k=0;k<=M;k++){
				for(int e=0;e<=2;e++){
					if(2*cc-e<0){
						continue;
					}
					ll cost=(a[i+1]-a[i])*(2*cc-e);
					if(k+cost>M){
						continue;
					}
					ll cur=dp[i][cc][k][e];
					//new
					dp[i+1][cc+1][k+cost][e]+=cur;
					if(e<=1){
						dp[i+1][cc+1][k+cost][e+1]+=(2-e)*cur;
					}
					//stick
					dp[i+1][cc][k+cost][e]+=(2*cc-e)*cur;
					dp[i+1][cc][k+cost][e+1]+=(2-e)*(cc-e)*cur;
					if(i==N-1){
						dp[i+1][cc][k+cost][e+1]+=cur;
					}
					//merge
					if(cc-e>=2){
						dp[i+1][cc-1][k+cost][e]+=(cc-e)*(cc-e-1)*cur;
					}
					if(cc-e>0&&e>0){
						dp[i+1][cc-1][k+cost][e]+=(cc-e)*e*cur;
					}
					if(e==2&&i==N-1){
						dp[i+1][cc-1][k+cost][e]+=cur;
					}
					dp[i+1][cc+1][k+cost][e]%=MOD;
					dp[i+1][cc+1][k+cost][e+1]%=MOD;
					dp[i+1][cc][k+cost][e]%=MOD;
					dp[i+1][cc][k+cost][e+1]%=MOD;
					dp[i+1][cc-1][k+cost][e]%=MOD;
				}
			}
		}
	}
	ll sum=0;
	for(int i=0;i<=M;i++){
		sum+=dp[N][1][i][2];
		sum%=MOD;
	}
	cout<<sum<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 144 ms 260380 KB Output is correct
3 Correct 99 ms 260368 KB Output is correct
4 Correct 108 ms 260428 KB Output is correct
5 Correct 117 ms 260444 KB Output is correct
6 Correct 101 ms 260384 KB Output is correct
7 Correct 101 ms 260428 KB Output is correct
8 Correct 102 ms 260424 KB Output is correct
9 Correct 103 ms 260404 KB Output is correct
10 Correct 105 ms 260448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 260456 KB Output is correct
2 Correct 101 ms 260460 KB Output is correct
3 Correct 105 ms 260428 KB Output is correct
4 Correct 102 ms 260408 KB Output is correct
5 Correct 106 ms 260456 KB Output is correct
6 Correct 103 ms 260468 KB Output is correct
7 Correct 101 ms 260452 KB Output is correct
8 Correct 108 ms 260428 KB Output is correct
9 Correct 107 ms 260404 KB Output is correct
10 Correct 100 ms 260420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 144 ms 260380 KB Output is correct
3 Correct 99 ms 260368 KB Output is correct
4 Correct 108 ms 260428 KB Output is correct
5 Correct 117 ms 260444 KB Output is correct
6 Correct 101 ms 260384 KB Output is correct
7 Correct 101 ms 260428 KB Output is correct
8 Correct 102 ms 260424 KB Output is correct
9 Correct 103 ms 260404 KB Output is correct
10 Correct 105 ms 260448 KB Output is correct
11 Correct 101 ms 260456 KB Output is correct
12 Correct 101 ms 260460 KB Output is correct
13 Correct 105 ms 260428 KB Output is correct
14 Correct 102 ms 260408 KB Output is correct
15 Correct 106 ms 260456 KB Output is correct
16 Correct 103 ms 260468 KB Output is correct
17 Correct 101 ms 260452 KB Output is correct
18 Correct 108 ms 260428 KB Output is correct
19 Correct 107 ms 260404 KB Output is correct
20 Correct 100 ms 260420 KB Output is correct
21 Correct 106 ms 260560 KB Output is correct
22 Correct 521 ms 260556 KB Output is correct
23 Correct 491 ms 260480 KB Output is correct
24 Correct 488 ms 260480 KB Output is correct
25 Correct 517 ms 260484 KB Output is correct
26 Correct 472 ms 260484 KB Output is correct
27 Correct 241 ms 260476 KB Output is correct
28 Correct 301 ms 260476 KB Output is correct
29 Correct 461 ms 260544 KB Output is correct
30 Correct 523 ms 260484 KB Output is correct