답안 #443979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
443979 2021-07-12T18:24:12 Z keta_tsimakuridze Skyscraper (JOI16_skyscraper) C++14
100 / 100
1040 ms 27360 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=6005;
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;
	int l1 = 0;
	for(int i=1;i<=n;i++) {
		cin >> a[i];
		l1 = max(l1,a[i]);
	} 
	l1 = 2*l1 + l;
	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 <= l1;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 <= l1;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<=l1;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(){
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 8 ms 1996 KB Output is correct
6 Correct 8 ms 2052 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 8 ms 1996 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 3 ms 716 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 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 8 ms 1996 KB Output is correct
6 Correct 8 ms 2052 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 8 ms 1996 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 3 ms 716 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 716 KB Output is correct
21 Correct 7 ms 972 KB Output is correct
22 Correct 202 ms 6360 KB Output is correct
23 Correct 1025 ms 26736 KB Output is correct
24 Correct 630 ms 17536 KB Output is correct
25 Correct 1040 ms 27360 KB Output is correct
26 Correct 796 ms 23400 KB Output is correct
27 Correct 137 ms 4156 KB Output is correct
28 Correct 155 ms 4528 KB Output is correct
29 Correct 304 ms 8580 KB Output is correct
30 Correct 980 ms 26708 KB Output is correct