Submission #135552

# Submission time Handle Problem Language Result Execution time Memory
135552 2019-07-24T08:11:16 Z 이온조(#3249) A Huge Tower (CEOI10_tower) C++14
40 / 100
1000 ms 39472 KB
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 9;
int A[22], dp[22][1100000], N, D;

int go(int ls, int msk) {
	if(msk == (msk&-msk)) return 1;
	if(dp[ls][msk] != -1) return dp[ls][msk];
	int ret = 0;
	for(int i=1; i<=N; i++) {
		if(i == ls || A[i] + D < A[ls] || (msk & (1 << (i-1))) == 0) continue;
		ret += go(i, msk - (1 << (ls-1)));
		ret %= MOD;
	}
	return dp[ls][msk] = ret;
}

int main() {
	scanf("%d%d",&N,&D);
	assert(N <= 20);
	for(int i=1; i<=N; i++) scanf("%d",&A[i]);
	int ans = 0;
	for(int i=1; i<=N; i++) for(int j=1; j<(1<<N); j++) dp[i][j] = -1;
	for(int i=1; i<=N; i++) ans += go(i, (1 << N) - 1), ans %= MOD;
	printf("%d", ans);
	return 0;
}

Compilation message

tower.cpp: In function 'int main()':
tower.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&N,&D);
  ~~~~~^~~~~~~~~~~~~~
tower.cpp:22:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf("%d",&A[i]);
                          ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 39472 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 9248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 528 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 476 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 436 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 404 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -