//in the name of Allah
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define req(i,s,e) for(int i=s;i<e;i++)
#define reqd(i,s,e,d) for(int i=s;i<e;i+=d)
#define Init ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int MX = 20*1000 + 100,mod = 1000 * 1000 * 1000 + 7;
int dp[MX][1100][20];
int inp[MX];
int d(int a, int b){
return abs(inp[a]-inp[b]);
}
int32_t main(){
int n,l;
cin>>n>>l;
req(i,0,n){
cin>>inp[i];
}
int r = 1<<n;
req(i,1,r){
if(__builtin_popcount(i)==1){
req(j,0,n){
if( i && (1<<j))
dp[i][0][j]=1;
}
}else{
req(j,1,l+1){
req(k,0,n){
if(i & (1<<k)){
req(h,0,n){
if(h!=k && i&(1<<h) && j-d(k,h)>-1){
dp[i][j][k]= (dp[i][j][k]+ dp[i^(1<<k)][j-d(k,h)][h])%mod;
}
}
}
}
}
}
}
int ans= 0;
req(i,0,n){
req(j,0,l+1){
ans =(ans+ dp[(1<<n)-1][j][i])%mod;
}
}
cout<<ans<<endl;
}
Compilation message
skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:34:17: warning: '<<' in boolean context, did you mean '<' ? [-Wint-in-bool-context]
if( i && (1<<j))
~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
4 ms |
972 KB |
Output is correct |
5 |
Correct |
47 ms |
17108 KB |
Output is correct |
6 |
Correct |
81 ms |
17108 KB |
Output is correct |
7 |
Correct |
18 ms |
17108 KB |
Output is correct |
8 |
Correct |
8 ms |
17108 KB |
Output is correct |
9 |
Correct |
71 ms |
17376 KB |
Output is correct |
10 |
Correct |
12 ms |
17376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
37456 KB |
Output is correct |
2 |
Correct |
1034 ms |
186728 KB |
Output is correct |
3 |
Correct |
583 ms |
186728 KB |
Output is correct |
4 |
Correct |
920 ms |
187664 KB |
Output is correct |
5 |
Correct |
1107 ms |
190576 KB |
Output is correct |
6 |
Correct |
1149 ms |
190576 KB |
Output is correct |
7 |
Correct |
454 ms |
190576 KB |
Output is correct |
8 |
Correct |
651 ms |
190576 KB |
Output is correct |
9 |
Correct |
1154 ms |
190576 KB |
Output is correct |
10 |
Correct |
1012 ms |
190576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
4 ms |
972 KB |
Output is correct |
5 |
Correct |
47 ms |
17108 KB |
Output is correct |
6 |
Correct |
81 ms |
17108 KB |
Output is correct |
7 |
Correct |
18 ms |
17108 KB |
Output is correct |
8 |
Correct |
8 ms |
17108 KB |
Output is correct |
9 |
Correct |
71 ms |
17376 KB |
Output is correct |
10 |
Correct |
12 ms |
17376 KB |
Output is correct |
11 |
Correct |
143 ms |
37456 KB |
Output is correct |
12 |
Correct |
1034 ms |
186728 KB |
Output is correct |
13 |
Correct |
583 ms |
186728 KB |
Output is correct |
14 |
Correct |
920 ms |
187664 KB |
Output is correct |
15 |
Correct |
1107 ms |
190576 KB |
Output is correct |
16 |
Correct |
1149 ms |
190576 KB |
Output is correct |
17 |
Correct |
454 ms |
190576 KB |
Output is correct |
18 |
Correct |
651 ms |
190576 KB |
Output is correct |
19 |
Correct |
1154 ms |
190576 KB |
Output is correct |
20 |
Correct |
1012 ms |
190576 KB |
Output is correct |
21 |
Incorrect |
17 ms |
190576 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |