Submission #729965

#TimeUsernameProblemLanguageResultExecution timeMemory
729965n0sk1llSkyscraper (JOI16_skyscraper)C++17
20 / 100
715 ms201740 KiB
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0) #define mp make_pair #define xx first #define yy second #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define all(x) x.begin(),x.end() #define ff(i,a,b) for (int i = a; i < b; i++) #define fff(i,a,b) for (int i = a; i <= b; i++) #define bff(i,a,b) for (int i = b-1; i >= a; i--) #define bfff(i,a,b) for (int i = b; i >= a; i--) using namespace std; long double typedef ld; unsigned int typedef ui; long long int typedef li; pair<int,int> typedef pii; pair<li,li> typedef pli; pair<ld,ld> typedef pld; vector<vector<int>> typedef graph; unsigned long long int typedef ull; //const int mod = 998244353; const int mod = 1000000007; //Note to self: Check for overflow int a[105]; int dp[16999][16][203]; void solve_megabrute(int n, int L) { sort(a,a+n); int ans=0; do { int tmp=0; ff(i,1,n) tmp+=abs(a[i]-a[i-1]); if (tmp<=L) ans++; } while (next_permutation(a,a+n)); cout<<ans<<"\n"; } void solve_bitmask(int n, int L) { ff(i,0,n) dp[(1<<i)][i][0]=1; ff(mask,0,(1<<n)) ff(lst,0,n) ff(dole,0,n) fff(t,0,L) if (((mask>>lst)&1) && ((mask>>dole)&1) && lst!=dole) { (dp[mask][lst][t+abs(a[lst]-a[dole])]+=dp[mask^(1<<lst)][dole][t])%=mod; } int sms=(1<<n)-1; int ans=0; ff(i,0,n) fff(t,0,L) (ans+=dp[sms][i][t])%=mod; cout<<ans<<"\n"; } int main() { FAST; int n,L; cin>>n>>L; ff(i,0,n) cin>>a[i]; if (n>14) return cout<<"necu radim",0; if (n<=8) solve_megabrute(n,L); else solve_bitmask(n,L); } //Note to self: Check for overflow
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...