Submission #443978

# Submission time Handle Problem Language Result Execution time Memory
443978 2021-07-12T18:22:12 Z keta_tsimakuridze Skyscraper (JOI16_skyscraper) C++14
20 / 100
624 ms 16072 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,L=3005;
int t,n,l,a[N],dp[2][N][L][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;
	for(int i=1;i<=n;i++) {
		cin >> a[i];
	} 
	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 <= 2*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 <= 2*l;sum++)
			for(int f1 = 0; f1<2; f1++){
				for(int f2=0; f2<2; f2++) {
					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<=2*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;
					
						///////////
						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;
	if(n==1) ans = 1;
	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 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 5 ms 1484 KB Output is correct
6 Correct 5 ms 1356 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 5 ms 1484 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 5 ms 1484 KB Output is correct
6 Correct 5 ms 1356 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 5 ms 1484 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 2 ms 588 KB Output is correct
21 Correct 5 ms 844 KB Output is correct
22 Correct 320 ms 9384 KB Output is correct
23 Incorrect 624 ms 16072 KB Output isn't correct
24 Halted 0 ms 0 KB -