Submission #1278482

#TimeUsernameProblemLanguageResultExecution timeMemory
1278482phuocrucppSkyscraper (JOI16_skyscraper)C++20
0 / 100
418 ms163576 KiB
/*ㅤ∧_∧
 ( ・∀・)
 ( つ┳⊃
ε (_)へ⌒ヽフ
 (  ( ・ω・)
 ◎―◎   ⊃  ⊃
BePhuongSuperSuwi
From TK4 - CHT
ㅤㅤ/ ⌒\____
  /・   )  \
 /ノへ ノ    /|
ノ    \\ |/_/_/*/


#include<bits/stdc++.h>
#define task "main"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define int long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii, ii>
#define base 341
#define MASK(i) (1ll << i)
#define oo 1e18
#define isOn(x,i) ((x) & MASK(i))
#define bitOn(x,i) ((x) | MASK(i))
#define bitOff(x,i) ((x) & ~MASK(i))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
using namespace std;
//using namespace __gnu_pbds;
const int maxn = 1e6 + 5;

int n, l, a[maxn];
int mod = 1e9 + 7;

namespace giai1{

    int dp[(1ll << 14) + 5][102][15];

    void solve() {

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (i == j) continue;
                int mask = (1ll << (i - 1)) + (1ll << (j - 1));
                dp[mask][abs(a[i] - a[j])][i - 1] = 1;
            }
        }

        for (int mask = 0; mask < (1 << n); mask++) {
            for (int s = 0; s <= l; s++) {
                vector <int> g, g2;
                for (int i = 0; i < n; i++) {
                    if (isOn(mask, i)) g.pb(i);
                    else g2.pb(i);
                }

                for (int x : g) {
                    if (dp[mask][s][x]) {
                        for (int y : g2) {
                            if (s + abs(a[x + 1] - a[y + 1]) <= l) {
                                int val = s + abs(a[x + 1] - a[y + 1]);
                                dp[bitOn(mask, y)][val][y] = (dp[bitOn(mask, y)][val][y] + dp[mask][s][x]) % mod;
                            }
                        }
                    }
                }
            }
        }

        int res = 0;
        for (int s = 0; s <= l; s++) {
            for (int i = 0; i < n; i++) {
                res = (res + dp[(1ll << n) - 1][s][i]);
            }
        }
        cout << res;
    }
}


main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if(fopen(task".inp","r")) {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin >> n >> l;
    for (int i = 1; i <= n; i++) cin >> a[i];

   // if (n <= 14 && l <= 100) giai1::solve();
   giai1::solve();
}


Compilation message (stderr)

skyscraper.cpp:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   88 | main() {
      | ^~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...