답안 #287888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287888 2020-09-01T06:03:16 Z 임성재(#5782) Skyscraper (JOI16_skyscraper) C++17
0 / 100
62 ms 33400 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n, l;
int a[1010];
int dp[5050][20][111];

int main() {
	fast;

	cin >> n >> l;

	for(int i=0; i<n; i++) {
		cin >> a[i];
	}

	for(int i=1; i<(1<<n); i++) {
		if(__builtin_popcount(i) == 1) {
			for(int j=0; j<n; j++) {
				if(i == (1<<j)) {
					dp[i][j][0] = 1;
				}
			}
			continue;
		}

		for(int j=0; j<n; j++) {
			if(~i & (1<<j)) continue;

			for(int k=0; k<=l; k++) {
				for(int m=0; m<n; m++) {
					if(m == j) continue;
					if(~i & (1<<m)) continue;
					if(abs(a[m] - a[j]) > k) continue;
					
					if(i == 7) cout << i << "!! " << j << " " << m << " " << k << endl; 

					dp[i][j][k] += dp[i ^ (1<<j)][m][k - abs(a[m] - a[j])];
				}
			}
		}
	}

	ll ans = 0;
	for(int i=0; i<n; i++) {
		for(int j=0; j<=l; j++) {
			ans += dp[(1<<n)-1][i][j];
		}
	}

	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 33400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -