Submission #102258

#TimeUsernameProblemLanguageResultExecution timeMemory
102258jasony123123Skyscraper (JOI16_skyscraper)C++11
100 / 100
112 ms19240 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[101], L; int dp[101][101][3][1001]; /* # 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 && e!=0) return 1; else return 0; } if (dp[i][g][e][sum] == 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); ret %= 1000000007; if (ret > 0) dp[i][g][e][sum] = ret; else dp[i][g][e][sum] = -1; } if (dp[i][g][e][sum] > 0) return dp[i][g][e][sum]; else return 0; } 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...