이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 21;
int a[N], n, d, 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 += rek(i, msk | (1 << i));
}
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 += rek(i, (1<<i));
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |