Submission #866463

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

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 10 ms 82520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 82520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 82524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 82520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 82524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 82520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1010 ms 82524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 82520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 82524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 166996 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 75 ms 166968 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 77 ms 166912 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 74 ms 166996 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 73 ms 166860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 167264 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 166784 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 76 ms 166992 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 75 ms 166996 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 93 ms 166820 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 116 ms 166996 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -