#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
// #pragma GCC optimize("Ofast,unroll-loops,inline")
// #pragma GCC target("avx2,bmi2,lzcnt")
#define pb push_back
#define all(x) x.begin(), x.end()
// #define int ll
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn = 1e6 + 10;
const int inf = 1e9 + 10;
const int mod = 1e9 + 7;
const int LOG = 21;
int n, L, a[maxn], b[maxn], pw2[maxn];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
pw2[0] = 1;
for (ll i = 1; i < 16; i ++)
pw2[i] = pw2[i - 1] * 2ll;
cin >> n >> L;
if (n == 1)
return cout << 1 << endl, 0;
for(ll i = 0; i < n; i ++)
cin >> a[i];
if(n < 9){
for(ll i = 0; i < n; i ++)b[i] = i;
ll ans = 0;
while(true) {
ll dif = 0;
for (ll i = 1; i < n; i ++)
dif += abs(a[b[i]] - a[b[i - 1]]);
if (dif <= L)
ans ++;
if (next_permutation(b, b + n))
ans = ans;
else
break;
}
return cout << ans << "\n", 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |