Submission #156950

#TimeUsernameProblemLanguageResultExecution timeMemory
156950justkiddinSkyscraper (JOI16_skyscraper)C++14
0 / 100
2036 ms376 KiB
// 𝒊𝒏𝒔𝒕𝒂𝒈𝒓𝒂𝒎: @___ᴊᴜꜱᴛᴋɪᴅᴅɪɴ #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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...