Submission #866467

# Submission time Handle Problem Language Result Execution time Memory
866467 2023-10-26T08:19:13 Z MisterReaper A Huge Tower (CEOI10_tower) C++17
45 / 100
1000 ms 262144 KB
//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

const int MOD = 1E9 + 9;

int dp[21][1 << 21];
int arr[21];

#define ONLINE_JUDGE
void solve() {
	memset(dp, -1, sizeof(dp));
	
	int n, d;
	cin >> n >> d;
	for(int i = 0; i < n; i++)
		cin >> arr[i];

	function <int(int, int)> f = [&](int last, int mask) -> int {
		if(mask == (1 << n) -1)
			return 1;
		
		if(dp[last][mask] != -1)
			return dp[last][mask];

		int res = 0;
		for(int i = 0; i < n; i++) {
			if(!(mask & (1 << i)) && (arr[i] <= d + arr[last])) {
				(res += f(i, mask | (1 << i))) %= MOD;
			}
		}

		assert(res >= 0);
		return dp[last][mask] = res;
	};

	int res = 0;
	for(int i = 0; i < n; i++) {
		(res += f(i, (1 << i))) %= MOD;
	}

	cout << res;
	
	return;
}

signed main() {
	#ifndef ONLINE_JUDGE
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int t = 1; //cin >> t;
	for(int i = 1; i <= t; i++) {
		solve();
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 173140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 172632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 172704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 172636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 172880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 172636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 938 ms 172800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 172888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 172668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2325 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2367 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2334 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2311 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2373 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2379 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2338 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2360 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2338 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2359 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2330 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -