Submission #102255

#TimeUsernameProblemLanguageResultExecution timeMemory
102255jasony123123Skyscraper (JOI16_skyscraper)C++11
5 / 100
43 ms512 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i,start,end) for(int i=start;i<(int)(end);i++) #define FORE(i,start,end) for(int i=start;i<=(int)end;i++) #define RFORE(i,start,end) for(int i = start; i>=end; i--) #define all(a) a.begin(), a.end() #define v vector #define mp make_pair typedef long long ll; typedef pair<int, int > pii; template<class T> void minn(T &a, T b) { a = min(a, b); } template<class T> void maxx(T &a, T b) { a = max(a, b); } void io() { #ifdef LOCAL_PROJECT freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #else #endif ios_base::sync_with_stdio(false); cin.tie(NULL); } /***************************JOI16_skyscraper*************************************/ int N, a[100], L; /* # ways to assign [i,N] with total abs <= L given start with g groups, e ends, sum base value */ ll f(int i, int g, int e, int sum) { sum += (2 * g + e)*(a[i] - a[i - 1]); if (sum > L) return 0; if (i == N) { if (g == 0) return 1; else return 0; } ll ret = 0; // join existing group if (g > 0 || e > 0) ret += f(i + 1, g, e, sum)*(2 * g + e); // make new group ret += f(i + 1, g + 1, e, sum)*(g + 1); // join two groups or ends if (g > 0) ret += f(i + 1, g - 1, e, sum)*(e + g - 1); // make new end, by itself if (e < 2) ret += f(i + 1, g, e + 1, sum)*(2 - e); // make new end, joined with a group if (e < 2 && g>0) ret += f(i + 1, g - 1, e + 1, sum)*(2 - e); return ret; } int main() { io(); cin >> N >> L; if (N == 1) { cout << 1 << "\n"; return 0; } FORE(i, 1, N) cin >> a[i]; sort(a + 1, a + 1 + N); cout << f(1, 0, 0, 0) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...