Submission #240517

#TimeUsernameProblemLanguageResultExecution timeMemory
240517rulerSkyscraper (JOI16_skyscraper)C++14
100 / 100
157 ms56824 KiB
// IOI 2021 #include <bits/stdc++.h> using namespace std; #define endl '\n' #define ends ' ' #define die(x) return cout << x << endl, 0 #define all(v) v.begin(), v.end() #define sz(x) (int)(x.size()) void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); } #define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__) typedef long long ll; typedef pair<int, int> pii; const int INF = 1e9; const ll MOD = 1e9 + 7; //////////////////////////////////////////////////////////////////// const int N = 1e2 + 5, L = 1e3 + 5; int A[N], DP[N][N][L][3]; void Add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } int SMul(int x, int y) { return 1LL * x * y % MOD; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); mt19937 Rnd(time(0)); int n, l; cin >> n >> l; for (int i = 1; i <= n; i++) cin >> A[i]; if (n == 1) die(1); sort(A + 1, A + n + 1); DP[1][0][0][1] = 2, DP[1][0][0][2] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j <= i; j++) for (int s = 0; s <= l; s++) for (int c = 0; c < 3; c++) { int x = A[i + 1] - A[i], y = 2 * j + c, d = s + x * y, p = DP[i][j][s][c]; if (d >= L || j + c == 0) continue; if (j) { Add(DP[i + 1][j - 1][d][c], SMul(j, p)); Add(DP[i + 1][j][d][c], SMul(j << 1, p)); Add(DP[i + 1][j + 1][d][c], SMul(j, p)); } if (c) { Add(DP[i + 1][j][d][c - 1], SMul(c, p)); Add(DP[i + 1][j][d][c], SMul(c, p)); Add(DP[i + 1][j + 1][d][c - 1], SMul(c, p)); Add(DP[i + 1][j + 1][d][c], SMul(c, p)); } } int ans = 0; for (int i = 0; i <= l; i++) Add(ans, DP[n][0][i][0]); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...