Submission #650038

# Submission time Handle Problem Language Result Execution time Memory
650038 2022-10-12T05:23:53 Z Gromp15 Skyscraper (JOI16_skyscraper) C++17
20 / 100
2000 ms 19548 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
using namespace std;
const int mod = 1e9+7;
void fadd(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}
int mul(int a, int b) {
    return (ll)a*b%mod;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, L; cin >> n >> L;
    vector<int> t(n);
    for (int &x : t) cin >> x;
    if (n == 1) {
        cout << 1 << '\n';
        return 0;
    }
    sort(t.begin(), t.end());
    vector<map<int, ar<int, 4>>> dp(n+1);
    // [# of components][total sum rn][(leftmost element filled) + (rightmost element filled)*2]
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        vector<map<int, ar<int, 4>>> dp2(n+1);
        for (int j = 0; j <= n; j++) {
            for (const auto &[l, val] : dp[j]) {
                for (int tp = 0; tp < 4; tp++) {
                    int num = val[tp];
                    if (!num) continue;
                    if (j > 1) { // merge
                        fadd(dp2[j-1][l+2*t[i]][tp], mul(num, j-1));
                    }
                    if (j > 0) { // add to comp
                        if (2*j-(tp&1)-(tp >> 1 & 1) > 0) fadd(dp2[j][l][tp], mul(num, 2*j-(tp&1)-(tp >> 1 & 1)));
                        if (!(tp & 1)) fadd(dp2[j][l+t[i]][tp|1], num);
                        if (!(tp >> 1 & 1)) fadd(dp2[j][l+t[i]][tp|2], num);
                    }
                    if (j+1 <= n) { // new comp
                        if (j+1-(tp&1)-(tp >> 1 & 1) > 0) fadd(dp2[j+1][l-2*t[i]][tp], mul(j+1-(tp&1)-(tp >> 1 & 1), num));
                        if (!(tp & 1)) fadd(dp2[j+1][l-t[i]][tp|1], num);
                        if (!(tp >> 1 & 1)) fadd(dp2[j+1][l-t[i]][tp|2], num);
                    }
                }
            }
        }
        swap(dp, dp2);
    }
    int ans = 0;
    for (int i = 0; i <= L; i++) { 
        fadd(ans, dp[1][i][3]);
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 5 ms 1200 KB Output is correct
6 Correct 5 ms 1236 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 18 ms 1332 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 17 ms 1364 KB Output is correct
5 Correct 20 ms 1620 KB Output is correct
6 Correct 10 ms 852 KB Output is correct
7 Correct 8 ms 572 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 13 ms 1300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 5 ms 1200 KB Output is correct
6 Correct 5 ms 1236 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 18 ms 1332 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 17 ms 1364 KB Output is correct
15 Correct 20 ms 1620 KB Output is correct
16 Correct 10 ms 852 KB Output is correct
17 Correct 8 ms 572 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 13 ms 1300 KB Output is correct
21 Correct 212 ms 4192 KB Output is correct
22 Execution timed out 2083 ms 19548 KB Time limit exceeded
23 Halted 0 ms 0 KB -