답안 #534915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534915 2022-03-09T06:48:28 Z devariaota A Huge Tower (CEOI10_tower) C++17
0 / 100
133 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 21, M = 1e9 + 9;
int a[N], n, d;
ll dp[N][(1<<N)];

ll rek(int pos, int msk){
  if(dp[pos][msk] != -1) return dp[pos][msk];
  if(__builtin_popcount(msk) == n-1){
    for(int i=0;i<n;i++)
    {
      if(msk & (1 << i)) continue;
      return dp[pos][msk] = a[i] <= a[pos] + d;
    }
  }
  ll ret = 0;
  for(int i=0;i<n;i++){
    if(msk & (1 << i)) continue;
    if(a[i] <= a[pos] + d)
      ret = (ret + rek(i, msk | (1 << i))) % M;
  }
  return dp[pos][msk] = ret;
}

int main(){
  cin.tie(0) -> ios_base::sync_with_stdio(0);

  memset(dp, -1, sizeof dp);
  cin >> n >> d;
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a, a+n);
  ll ans = 0;
  for(int i=0;i<n;i++)
    ans = (ans + rek(i, (1<<i))) % M;
  cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 101 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 98 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 99 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 109 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 111 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 106 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 133 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 96 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 100 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 98 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 95 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 100 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 100 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 99 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 123 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 104 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 121 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -