Submission #866465

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

const int MOD = 1E9 + 9;

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

#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;
			}
		}

		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 20 ms 164444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 164440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 164440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 164444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 164440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 164444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 164512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 164432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 164592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2264 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 2289 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2381 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2337 ms 262152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2351 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2387 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2369 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2315 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2364 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2343 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -