Submission #102603

#TimeUsernameProblemLanguageResultExecution timeMemory
102603MinnakhmetovSkyscraper (JOI16_skyscraper)C++14
100 / 100
1100 ms20548 KiB
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <cstring> #include <unordered_map> #include <unordered_set> using namespace std; #define ll long long #define all(aaa) aaa.begin(), aaa.end() #pragma warning(disable : 4996) const int N = 101, S = 2e5 + 1, MOD = 1e9 + 7; int a[N], b[N], dp[2][3][N][S]; void f(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); int n, l; cin >> n >> l; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); reverse(a, a + n); for (int i = 0; i < n; i++) { a[i] -= a[n - 1]; } for (int i = n - 1; i >= 0; i--) { b[i] += b[i + 1] + a[i]; } dp[1][0][0][0] = 1; dp[1][2][0][a[0] + a[0]] = 1; dp[1][1][0][a[0]] = 2; for (int i = 1, q = 1; i < n; i++, q ^= 1) { int mx = b[i + 1] * 2 + l; for (int x = 0; x < 3; x++) { for (int j = 0; j < min(i, n - i + 1); j++) { for (int k = 0; k <= (a[i - 1] << 1); k++) { if (dp[q][x][j][k]) { int cur = dp[q][x][j][k]; if (x) { int cur2 = cur * x; if (cur2 >= MOD) cur2 -= MOD; f(dp[q ^ 1][x - 1][j][k - a[i]], cur2); f(dp[q ^ 1][x][j][k], cur2); if (k + a[i] <= mx) f(dp[q ^ 1][x - 1][j + 1][k + a[i]], cur2); if (k + a[i] + a[i] <= mx) f(dp[q ^ 1][x][j + 1][k + a[i] + a[i]], cur2); } cur = cur * (ll)j % MOD; if (j) { int cur2 = cur + cur; if (cur2 >= MOD) cur2 -= MOD; f(dp[q ^ 1][x][j][k], cur2); if (k + a[i] + a[i] <= mx) f(dp[q ^ 1][x][j + 1][k + a[i] + a[i]], cur); f(dp[q ^ 1][x][j - 1][k - a[i] - a[i]], cur); } dp[q][x][j][k] = 0; } } } } a[i] += a[i - 1]; } int ans = 0; for (int i = 0; i <= l; i++) { f(ans, dp[n & 1][0][0][i]); } cout << ans; return 0; }

Compilation message (stderr)

skyscraper.cpp:41:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...