Submission #443960

# Submission time Handle Problem Language Result Execution time Memory
443960 2021-07-12T16:05:06 Z keta_tsimakuridze Skyscraper (JOI16_skyscraper) C++14
15 / 100
6 ms 3920 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=105,mod=1e9+7,M=6005;
int t,n,l,a[N],dp[2][N][M][2][2],cnt,fix[N];
vector<int>v;
void go(int cur){
	if(cur==n+1) {
		int ans = 0;
		for(int i=1;i<v.size();i++) {
			ans+=abs(a[v[i]] - a[v[i-1]]);
		} 
		if(ans <= l) cnt++;
	}
	for(int i=1;i<=n;i++){
		if(!fix[i]) {
			fix[i] = 1;
			v.push_back(i);
			go(cur+1);
			v.pop_back();
			fix[i] = 0;
		}
	}
}
 main(){
	cin>>n>>l;
	int L = 0;
	for(int i=1;i<=n;i++) {
		cin >> a[i];
		L = max(L,a[i]);
	} 
	L = 4000;
	sort(a+1,a+n+1);
	dp[0][1][(a[2] - a[1]) * 2][0][0] = 1;
	dp[0][1][a[2] - a[1] ][0][1] = dp[0][1][a[2] - a[1]][1][0] = 1;
	a[n+1] = a[n];
	for(int i=2;i<=n;i++){ 
		for(int j=1;j<=i;j++) 
		for(int sum = 0;sum <= L;sum++)
		for(int f1 = 0; f1<2; f1++)
		for(int f2=0; f2<2; f2++) dp[1][j][sum][f1][f2] = 0;
		for(int j=1;j<=i;j++) {
			for(int sum = 0;sum <= L;sum++)
			for(int f1 = 0; f1<2; f1++){
				for(int f2=0; f2<2; f2++) {
				if(sum + (j*2 - f1 - f2) * (a[i+1] - a[i]) <= L)	
				dp[1][j][sum + (j*2 - f1 - f2) * (a[i+1] - a[i]) ][f1][f2] = dp[0][j][sum][f1][f2];
					dp[0][j][sum][f1][f2] = 0;
				}
			}
		} 
		int diff = a[i+1] - a[i];
		for(int j=1; j<=i; j++) {
			for(int sum=0; sum<=l;sum++){
				for(int f1=0; f1<2;f1++){
					for(int f2=0;f2<2;f2++) {
						if(f1) {
							// dasackisshi
							if(!f2) dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][0][f2]*j%mod ;
							else {
								if(i == n) dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][0][f2];
								else dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][0][f2] * (j-1)%mod;
							}
							if(sum - diff >= 0)dp[0][j][sum][f1][f2] += dp[1][j-1][sum - diff][0][f2]; 
						}
						if(f2) {
							if(!f1) dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][f1][0]*j%mod ;
							else {
								if(i == n) dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][f1][0];
								else dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][f1][0] * (j-1)%mod;
							}
							if(sum - diff >= 0)dp[0][j][sum][f1][f2] += dp[1][j-1][sum - diff][f1][0]; 
						}
						
						////////////
						dp[0][j][sum][f1][f2] += dp[1][j][sum][f1][f2] * (2*j - f1 - f2)%mod;
					
						///////////
						if(sum >= 2*diff)dp[0][j][sum][f1][f2] += dp[1][j-1][sum - 2*diff][f1][f2];
						//////////
						if(!f1 && !f2) dp[0][j][sum][f1][f2] += dp[1][j+1][sum + 2*diff][f1][f2] * (j * (j + 1)%mod)%mod;
						else if(f1 && f2 ){
							if(j==1 && i!=n) {}
							else 
							if(j==1) {
									dp[0][j][sum][f1][f2] += dp[1][j+1][sum + 2*diff][f1][f2]%mod;
							}
							else {
								dp[0][j][sum][f1][f2] += dp[1][j+1][sum + 2*diff][f1][f2] * (j * (j - 1)%mod)%mod;
							}
						} 
						else dp[0][j][sum][f1][f2] += dp[1][j+1][sum + 2*diff][f1][f2] * (j * j%mod)%mod;
						dp[0][j][sum][f1][f2]%=mod;
					}
				}
			}
		}
	}
	int ans = 0;
	for(int sum=0;sum<=l;sum++)
	ans += dp[0][1][sum][1][1],ans%=mod;
	cout<<ans<<endl;
}

Compilation message

skyscraper.cpp: In function 'void go(long long int)':
skyscraper.cpp:12:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for(int i=1;i<v.size();i++) {
      |               ~^~~~~~~~~
skyscraper.cpp: At global scope:
skyscraper.cpp:27:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 |  main(){
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3324 KB Output is correct
2 Correct 6 ms 3808 KB Output is correct
3 Correct 5 ms 3920 KB Output is correct
4 Correct 6 ms 3916 KB Output is correct
5 Correct 6 ms 3916 KB Output is correct
6 Correct 5 ms 3916 KB Output is correct
7 Correct 5 ms 3916 KB Output is correct
8 Correct 6 ms 3916 KB Output is correct
9 Correct 6 ms 3916 KB Output is correct
10 Correct 6 ms 3920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -