// 𝒊𝒏𝒔𝒕𝒂𝒈𝒓𝒂𝒎: @___ᴊᴜꜱᴛᴋɪᴅᴅɪɴ
#include <bits/stdc++.h>
#define ll long long
#define Pii pair<int, int>
#define Piii pair<int, Pii>
#define _mp make_pair
#define _pb push_back
#define st first
#define nd second
#define whole(x) x.begin(), x.end()
#define Reset(x) memset(x, 0, sizeof(x))
#define PI acos(-1)
#define TASK ""
const int M = 1e5+8;
const int oo = 1e9+7;
using namespace std;
// mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int n, k, a[M], b[M];
long long Res = 0;
bool c[M];
int _calc(){
long long Rest = 0;
for(int i = 2; i <= n; i++){
Rest += abs(a[b[i]] - a[b[i-1]]);
if(Rest > k) return 0;
// cout << a[b[i]] << ' ';
}
// cout << '\n';
return 1;
}
void _try(int i){
for(int j = 1; j <= n; j++){
if(c[j] == true)// || ( abs(a[b[i]] - a[b[i-1]]) > k && i != 1))
continue;
b[i] = j;
c[j] = true;
if(i == n)
Res = (Res + _calc())%oo;
else
_try(i+1);
c[j] = false;
}
}
int main(int argc, char const *argv[]){
// freopen("test.txt", "r", stdin);
// freopen(TASK".inp", "r", stdin);
// freopen(TASK".out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
c[i] = false;
}
// memset(c, 0, sizeof(c));
_try(1);
cout << Res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2045 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Execution timed out |
2045 ms |
376 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |