Submission #849968

# Submission time Handle Problem Language Result Execution time Memory
849968 2023-09-15T15:07:22 Z fanwen Skyscraper (JOI16_skyscraper) C++17
100 / 100
123 ms 130536 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }

template <class A, class B> bool minimize(A &a, B b)  { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b)  { if (a < b) { a = b; return true; } return false; }

template <int Mod> 
struct Modular {
private :
    int val;
    static int inverse(int a, int b) {
        a %= b;
        assert(a);
        if(a == 1) return 1;
        return int(b - (long long) inverse(b, a) * (long long) b / a);
    }
public :
    Modular(long long x = 0) : val(x % Mod) { if(val < 0) val += Mod; }

    friend bool operator == (const Modular &a, const Modular &b) { return a.val == b.val; }
    friend bool operator != (const Modular &a, const Modular &b) { return a.val != b.val; }

    Modular& operator = (const long long &x) { val = x % Mod; if(val < 0) val += Mod; return *this; }
    Modular& operator = (const Modular &x) { val = x.val; return *this; }

    friend istream & operator >> (istream &in, Modular &a) { long long x; in >> x; a = Modular(x); return in; }
    friend ostream & operator << (ostream &out, const Modular &a) { return out << a.val; }

    explicit operator int() const { return val; }
    explicit operator bool() const { return val > 0; }

    Modular inv() const {
        Modular res;
        res.val = inverse(val, Mod);
        return res;
    }

    Modular operator ++() { (*this) += 1; return *this; }
    Modular operator --() { (*this) -= 1; return *this; }
    Modular operator ++(int) { (*this) += 1; return *this - 1; }
    Modular operator --(int) { (*this) -= 1; return *this + 1; }

    Modular operator + () const { return *this; }
    Modular operator - () const {
        Modular res;
        res.val = (val ? Mod - val : 0);
        return res;
    }

    Modular& operator += (const Modular &a) {
        val += a.val;
        if(val >= Mod) val -= Mod;
        return *this;
    }
    Modular& operator -= (const Modular &a) {
        val -= a.val;
        if(val < 0) val += Mod;
        return *this;
    }
    Modular& operator *= (const Modular &a) {
        val = 1LL * val * a.val % Mod;
        return *this;
    }
    Modular& operator /= (const Modular &a) {
        (*this) *= a.inv();
        return *this;
    }
    
    friend Modular operator + (const Modular &a, const Modular &b) { return Modular(a) += b; }
    friend Modular operator - (const Modular &a, const Modular &b) { return Modular(a) -= b; }
    friend Modular operator * (const Modular &a, const Modular &b) { return Modular(a) *= b; }
    friend Modular operator / (const Modular &a, const Modular &b) { return Modular(a) /= b; }
};

// const int Mod = 998244353;
// const int Mod = 1e9 + 9; // 1000000009 
const int Mod = 1e9 + 7; // 1000000007

using Modint = Modular <Mod>;

template <class T> T pow(T a, long long b) {
    T ans = 1, mul = a;
    for (; b; b >>= 1) {
        if(b & 1LL) ans *= mul;
        mul *= mul;
    }
    return ans;
}

const int MAXN = 105, MAXL = 1005;

int N, L, a[MAXN];
Modint dp[MAXN][MAXN][MAXL][3];

void you_make_it(void) {
    cin >> N >> L;
    FOR(i, 1, N) cin >> a[i];
    sort(a + 1, a + N + 1);
    if(N == 1) {
    	cout << 1;
    	return;
    }
    dp[1][1][0][0] = 1;
    dp[1][1][0][1] = 2;
    FOR(i, 2, N) FORE(j, 1, i) FOR(cost, 0, L) FOR(e, 0, 2) {
    	int new_cost = cost + (a[i] - a[i - 1]) * (2 * j - e);
    	if(new_cost > L) continue;

    	dp[i][j + 1][new_cost][e] += dp[i - 1][j][cost][e] * (j + 1 - e);
    	if(e < 2) {
    		dp[i][j + 1][new_cost][e + 1] += dp[i - 1][j][cost][e] * (2 - e);
    		dp[i][j][new_cost][e + 1] += dp[i - 1][j][cost][e] * (2 - e);
    	}
    	dp[i][j][new_cost][e] += dp[i - 1][j][cost][e] * (2 * j - e);
    	dp[i][j - 1][new_cost][e] += dp[i - 1][j][cost][e] * (j - 1);
    }
    Modint ans = 0;
    FOR(i, 0, L) ans += dp[N][1][i][2];
    cout << ans;
}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.
# Verdict Execution time Memory Grader output
1 Correct 23 ms 130384 KB Output is correct
2 Correct 24 ms 130384 KB Output is correct
3 Correct 23 ms 130412 KB Output is correct
4 Correct 23 ms 130388 KB Output is correct
5 Correct 24 ms 130392 KB Output is correct
6 Correct 23 ms 130392 KB Output is correct
7 Correct 23 ms 130392 KB Output is correct
8 Correct 24 ms 130384 KB Output is correct
9 Correct 24 ms 130384 KB Output is correct
10 Correct 24 ms 130392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 130384 KB Output is correct
2 Correct 23 ms 130384 KB Output is correct
3 Correct 24 ms 130456 KB Output is correct
4 Correct 23 ms 130392 KB Output is correct
5 Correct 23 ms 130384 KB Output is correct
6 Correct 24 ms 130392 KB Output is correct
7 Correct 24 ms 130384 KB Output is correct
8 Correct 24 ms 130384 KB Output is correct
9 Correct 24 ms 130396 KB Output is correct
10 Correct 24 ms 130384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 130384 KB Output is correct
2 Correct 24 ms 130384 KB Output is correct
3 Correct 23 ms 130412 KB Output is correct
4 Correct 23 ms 130388 KB Output is correct
5 Correct 24 ms 130392 KB Output is correct
6 Correct 23 ms 130392 KB Output is correct
7 Correct 23 ms 130392 KB Output is correct
8 Correct 24 ms 130384 KB Output is correct
9 Correct 24 ms 130384 KB Output is correct
10 Correct 24 ms 130392 KB Output is correct
11 Correct 23 ms 130384 KB Output is correct
12 Correct 23 ms 130384 KB Output is correct
13 Correct 24 ms 130456 KB Output is correct
14 Correct 23 ms 130392 KB Output is correct
15 Correct 23 ms 130384 KB Output is correct
16 Correct 24 ms 130392 KB Output is correct
17 Correct 24 ms 130384 KB Output is correct
18 Correct 24 ms 130384 KB Output is correct
19 Correct 24 ms 130396 KB Output is correct
20 Correct 24 ms 130384 KB Output is correct
21 Correct 25 ms 130384 KB Output is correct
22 Correct 105 ms 130392 KB Output is correct
23 Correct 121 ms 130532 KB Output is correct
24 Correct 110 ms 130492 KB Output is correct
25 Correct 121 ms 130536 KB Output is correct
26 Correct 108 ms 130532 KB Output is correct
27 Correct 56 ms 130388 KB Output is correct
28 Correct 68 ms 130528 KB Output is correct
29 Correct 102 ms 130532 KB Output is correct
30 Correct 123 ms 130528 KB Output is correct