답안 #960383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960383 2024-04-10T11:06:05 Z amirhoseinfar1385 Skyscraper (JOI16_skyscraper) C++17
100 / 100
949 ms 98712 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=100+10,maxl=1000+10,mod=1e9+7;
int dp[maxn][maxn][maxl][4],l,n;
vector<int>all;
void vorod(){
	cin>>n>>l;
	all.resize(n);
	for(int i=0;i<n;i++){
		cin>>all[i];
	}
	sort(all.begin(),all.end());
	int z=all.back();
	all.push_back(z);
}

inline void add(int a,int b,int c,int d,int aa,int bb,int cc,int dd,int w){
//	if(aa==0&&dd==3&&dp[aa][bb][cc][dd]!=0){
//		cout<<"wtf"<<endl;
//	}
	long long e=1ll*dp[aa][bb][cc][dd]*w%mod;
	dp[a][b][c][d]+=e;
	dp[a][b][c][d]%=mod;
}

void upd(int ind,int ted,int dis,int tar){
//	cout<<ind<<" "<<ted<<" "<<dis<<" "<<tar<<" "<<dp[ind][ted][dis][tar]<<" "<<all[ind+2]-all[ind+1]<<endl;
	long long val=dp[ind][ted][dis][tar];
	long long ezaf=all[ind+2]-all[ind+1],te=ted*2+__builtin_popcount(tar);
	if(ted>0){
		//vas00;
		if(dis+ezaf*(te+2)<=l){
			add(ind+1,ted+1,dis+ezaf*(te+2),tar,ind,ted,dis,tar,ted);
		}

		//vas10;
		if(dis+ezaf*(te)<=l){
			add(ind+1,ted,dis+ezaf*(te),tar,ind,ted,dis,tar,ted);
		}

		//vas01;
		if(dis+ezaf*(te)<=l){
			add(ind+1,ted,dis+ezaf*(te),tar,ind,ted,dis,tar,ted);
		}

		//vas11;
		if(dis+ezaf*(te-2)<=l){
			add(ind+1,ted-1,dis+ezaf*(te-2),tar,ind,ted,dis,tar,ted);
		}

	}
	if(tar&1){
		//vas00;
		if(dis+ezaf*(te+2)<=l){
			add(ind+1,ted+1,dis+ezaf*(te+2),tar,ind,ted,dis,tar,1);
		}

		//vas10;
		if(dis+ezaf*(te)<=l){
			add(ind+1,ted,dis+ezaf*(te),tar,ind,ted,dis,tar,1);
		}

		//vas01;
		if(dis+ezaf*(te+1)<=l){
			add(ind+1,ted+1,dis+ezaf*(te+1),tar^1,ind,ted,dis,tar,1);
		}

		//vas11;
		if(dis+ezaf*(te-1)<=l){
			add(ind+1,ted,dis+ezaf*(te-1),tar^1,ind,ted,dis,tar,1);
		}
	}
	if(tar&2){
		//vas00;
		if(dis+ezaf*(te+2)<=l){
			add(ind+1,ted+1,dis+ezaf*(te+2),tar,ind,ted,dis,tar,1);
		}

		//vas10;
		if(dis+ezaf*(te+1)<=l){
			add(ind+1,ted+1,dis+ezaf*(te+1),tar^2,ind,ted,dis,tar,1);
		}

		//vas01;
		if(dis+ezaf*(te)<=l){
			add(ind+1,ted,dis+ezaf*(te),tar,ind,ted,dis,tar,1);
		}

		//vas11;
		if(dis+ezaf*(te-1)<=l){
			add(ind+1,ted,dis+ezaf*(te-1),tar^2,ind,ted,dis,tar,1);
		}
	}
}

void pre(){
	dp[0][0][0][0]=1;
	dp[0][0][all[1]-all[0]][1]=1;
	dp[0][0][all[1]-all[0]][2]=1;
	dp[0][0][2*(all[1]-all[0])][3]=1;
	for(int i=1;i<n;i++){
		for(int j=0;j<n;j++){
			for(int h=0;h<=l;h++){
				for(int z=0;z<4;z++){
					upd(i-1,j,h,z);
				}
			}
		}
	}
}

void khor(){
	long long mainres=0;
	for(int i=0;i<=l;i++){
		mainres+=dp[n-1][0][i][0];
	}
	mainres%=mod;
	cout<<mainres<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen("inp.txt","r",stdin);
	vorod();
	//cout<<"salam"<<endl;
	pre();
	khor();
}

Compilation message

skyscraper.cpp: In function 'void upd(int, int, int, int)':
skyscraper.cpp:28:12: warning: unused variable 'val' [-Wunused-variable]
   28 |  long long val=dp[ind][ted][dis][tar];
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 5 ms 860 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 6 ms 1116 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 972 KB Output is correct
6 Correct 3 ms 1368 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 5 ms 860 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 6 ms 1116 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 2 ms 1116 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 972 KB Output is correct
16 Correct 3 ms 1368 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 2 ms 1116 KB Output is correct
19 Correct 3 ms 1372 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 6 ms 3932 KB Output is correct
22 Correct 805 ms 92420 KB Output is correct
23 Correct 916 ms 86104 KB Output is correct
24 Correct 830 ms 92592 KB Output is correct
25 Correct 949 ms 89024 KB Output is correct
26 Correct 814 ms 85604 KB Output is correct
27 Correct 305 ms 63572 KB Output is correct
28 Correct 410 ms 72424 KB Output is correct
29 Correct 770 ms 98712 KB Output is correct
30 Correct 937 ms 88576 KB Output is correct