Submission #1037127

# Submission time Handle Problem Language Result Execution time Memory
1037127 2024-07-28T08:00:27 Z Shayan86 Skyscraper (JOI16_skyscraper) C++14
100 / 100
57 ms 79444 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define Mp          make_pair
#define sep         ' '
#define endl        '\n'
#define F	        first
#define S	        second
#define pb          push_back
#define SZ(x)       (int)x.size()
#define all(x)      (x).begin(),(x).end()
#define kill(res)	cout << res << '\n', exit(0);
#define set_dec(x)	cout << fixed << setprecision(x);
#define fast_io     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll N = 109;
const ll M = 1009;
const ll Mod = 1e9 + 7;

ll n, L, a[N], dp[N][N][M][3];

int main(){
    fast_io;
    
    cin >> n >> L;

    for(int i = 1; i <= n; i++) cin >> a[i];
    a[n+1] = 2e4;

    sort(a+1, a+n+1);

    if(n == 1) kill(1);

    dp[1][1][2*(a[2]-a[1])][0] = 1;
    dp[1][1][a[2]-a[1]][1] = 2;

    for(int i = 2; i <= n; i++){
        for(int j = 1; j <= i; j++){
            for(int k = 0; k <= L; k++){
                for(int o = 0; o < 3; o++){
                    int dist = (a[i+1] - a[i]) * (2*j - o);
                    if(k < dist) continue;

                    dp[i][j][k][o] += (j-o) * dp[i-1][j-1][k-dist][o];
                    if(o) dp[i][j][k][o] += (3-o) * dp[i-1][j-1][k-dist][o-1];
                    dp[i][j][k][o] += (2*j-o) * dp[i-1][j][k-dist][o];
                    if(o) dp[i][j][k][o] += (3-o) * dp[i-1][j][k-dist][o-1];
                    dp[i][j][k][o] += j * dp[i-1][j+1][k-dist][o];

                    dp[i][j][k][o] %= Mod;
                }
            }
        }
    }

    ll res = 0;
    for(int k = 0; k <= L; k++) res += dp[n][1][k][2];
    res %= Mod;

    cout << res;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 1 ms 2516 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 3160 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 3028 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 1 ms 2516 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 3160 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 0 ms 2652 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 3028 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 40 ms 67520 KB Output is correct
23 Correct 51 ms 78420 KB Output is correct
24 Correct 47 ms 76880 KB Output is correct
25 Correct 56 ms 79360 KB Output is correct
26 Correct 44 ms 73820 KB Output is correct
27 Correct 21 ms 43356 KB Output is correct
28 Correct 25 ms 49776 KB Output is correct
29 Correct 44 ms 74836 KB Output is correct
30 Correct 57 ms 79444 KB Output is correct