//#pragma GCC optimize("O2,unroll-loops")
//#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
return l+rng()%(r-l+1);
}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define forinc(x,a,b) for(int x=a;x<=b;x++)
#define fordec(x,a,b) for(int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<long long,long long>
#define getbit(x,i) ((x>>(i))&1)
#define batbit(x,i) (x|(1ll<<(i)))
#define tatbit(x,i) (x&~(1<<(i)))
#define gg exit(0);
#define all(a) a.begin() , a.end()
const int N = 14;
const int mod = 1e9 + 7;
int n, L;
int a[20];
int f[1<<15][15][210];
main()
{
fasty;
cin >> n >> L;
forinc(i,1,n) cin >> a[i];
f[0][0][0] = 1;
if(n <= 10)
{
int cnt=0;
sort(a+1 , a+n+1);
do
{
int sum=0;
forinc(i,1,n-1) sum += abs(a[i] - a[i+1]);
if(sum <= L) cnt++;
}while(next_permutation(a+1 , a+n + 1));
cout << cnt;
return 0;
}
for(int tt =0 ; tt <= (1<<n) - 1 ; tt++) forinc(i , 0 , n) forinc(l , 0 , L) if(f[tt][i][l])
{
forinc(j , 1 , n) if(!getbit(tt , j-1))
{
int kc=0;
if(tt != 0) kc = l + abs(a[j] - a[i]);
int tt2 = batbit(tt , j-1);
f[tt2][j][kc] = (f[tt2][j][kc] + f[tt][i][l])%mod;
}
}
int res=0;
forinc(i,1,n) forinc(l , 0 , L) res = (res + f[(1<<n) - 1][i][l])%mod;
cout << res;
}
Compilation message
skyscraper.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
29 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
46136 KB |
Output is correct |
2 |
Correct |
149 ms |
194792 KB |
Output is correct |
3 |
Correct |
224 ms |
193984 KB |
Output is correct |
4 |
Correct |
148 ms |
194660 KB |
Output is correct |
5 |
Correct |
131 ms |
194812 KB |
Output is correct |
6 |
Correct |
231 ms |
194576 KB |
Output is correct |
7 |
Correct |
132 ms |
193408 KB |
Output is correct |
8 |
Correct |
216 ms |
193900 KB |
Output is correct |
9 |
Correct |
252 ms |
194120 KB |
Output is correct |
10 |
Correct |
152 ms |
194508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
43 ms |
46136 KB |
Output is correct |
12 |
Correct |
149 ms |
194792 KB |
Output is correct |
13 |
Correct |
224 ms |
193984 KB |
Output is correct |
14 |
Correct |
148 ms |
194660 KB |
Output is correct |
15 |
Correct |
131 ms |
194812 KB |
Output is correct |
16 |
Correct |
231 ms |
194576 KB |
Output is correct |
17 |
Correct |
132 ms |
193408 KB |
Output is correct |
18 |
Correct |
216 ms |
193900 KB |
Output is correct |
19 |
Correct |
252 ms |
194120 KB |
Output is correct |
20 |
Correct |
152 ms |
194508 KB |
Output is correct |
21 |
Runtime error |
7 ms |
588 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |