Submission #23300

# Submission time Handle Problem Language Result Execution time Memory
23300 2017-05-06T04:25:56 Z duongthoi1999 Skyscraper (JOI16_skyscraper) C++14
100 / 100
76 ms 4768 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 105;
const ld eps = 1e-9;

void add(int &a, ll b) {
    b %= mod;
    a += b;
    while (a >= mod) a -= mod;
}

int n, L, a[maxn];
int f[2][maxn][maxn * 10][3];

void trau() {
    int cnt = 0;
    do {
        int res = 0;
        rep(i, 1, n) res += abs(a[i] - a[i + 1]);
        if(res <= L) cnt ++;
    } while (next_permutation(a + 1, a + 1 + n));
    cout << cnt << endl;
}

int main() {
    //freopen("test.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> L;
    rep(i, 1, n + 1) cin >> a[i];
    sort(a + 1, a + 1 + n);
    a[n + 1] = 12345;
    if(a[2] - a[1] <= L) f[1][1][a[2] - a[1]][1] = 2;
    if(2 * (a[2] - a[1]) <= L) f[1][1][2 * (a[2] - a[1])][0] = 1;
    rep(i, 1, n) {
        int d = a[i + 2] - a[i + 1];
        rep(j, 1, i + 1) {
            rep(k, 0, L + 1) {
                rep(e, 0, min(j + 1, 3)) {
                    if(!f[i & 1][j][k][e]) continue;
                    if(e < 2) {
                        if(k + (2 * (j + 1) - (e + 1)) * d <= L)
                            add(f[(i + 1) & 1][j + 1][k + (2 * (j + 1) - (e + 1)) * d][e + 1], (2 - e) * f[i & 1][j][k][e]);
                        if(k + (2 * j - (e + 1)) * d <= L)
                            add(f[(i + 1) & 1][j][k + (2 * j - (e + 1)) * d][e + 1], (2 - e) * f[i & 1][j][k][e]);
                    }
                    if(k + (2 * (j + 1) - e) * d <= L)
                        add(f[(i + 1) & 1][j + 1][k + (2 * (j + 1) - e) * d][e], 1LL * (j - e + 1) * f[i & 1][j][k][e]);
                    if(k + (2 * j - e) * d <= L)
                        add(f[(i + 1) & 1][j][k + (2 * j - e) * d][e], 1LL * (2 * j - e) * f[i & 1][j][k][e]);
                    if(j > 1 && k + (2 * (j - 1) - e) * d <= L)
                        add(f[(i + 1) & 1][j - 1][k + (2 * (j - 1) - e) * d][e], 1LL * (j - 1) * f[i & 1][j][k][e]);
                }
            }
        }
        memset(f[i & 1], 0, sizeof f[i & 1]);
    }
    int res = 0;
    rep(i, 0, L + 1) add(res, f[n & 1][1][i][2]);
    if(n == 1) res = 1;
    cout << res << endl;
    //trau();
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 4768 KB Output is correct
2 Correct 0 ms 4768 KB Output is correct
3 Correct 0 ms 4768 KB Output is correct
4 Correct 0 ms 4768 KB Output is correct
5 Correct 3 ms 4768 KB Output is correct
6 Correct 0 ms 4768 KB Output is correct
7 Correct 0 ms 4768 KB Output is correct
8 Correct 0 ms 4768 KB Output is correct
9 Correct 0 ms 4768 KB Output is correct
10 Correct 0 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4768 KB Output is correct
2 Correct 0 ms 4768 KB Output is correct
3 Correct 0 ms 4768 KB Output is correct
4 Correct 0 ms 4768 KB Output is correct
5 Correct 0 ms 4768 KB Output is correct
6 Correct 0 ms 4768 KB Output is correct
7 Correct 0 ms 4768 KB Output is correct
8 Correct 0 ms 4768 KB Output is correct
9 Correct 0 ms 4768 KB Output is correct
10 Correct 0 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4768 KB Output is correct
2 Correct 0 ms 4768 KB Output is correct
3 Correct 0 ms 4768 KB Output is correct
4 Correct 0 ms 4768 KB Output is correct
5 Correct 3 ms 4768 KB Output is correct
6 Correct 0 ms 4768 KB Output is correct
7 Correct 0 ms 4768 KB Output is correct
8 Correct 0 ms 4768 KB Output is correct
9 Correct 0 ms 4768 KB Output is correct
10 Correct 0 ms 4768 KB Output is correct
11 Correct 0 ms 4768 KB Output is correct
12 Correct 0 ms 4768 KB Output is correct
13 Correct 0 ms 4768 KB Output is correct
14 Correct 0 ms 4768 KB Output is correct
15 Correct 0 ms 4768 KB Output is correct
16 Correct 0 ms 4768 KB Output is correct
17 Correct 0 ms 4768 KB Output is correct
18 Correct 0 ms 4768 KB Output is correct
19 Correct 0 ms 4768 KB Output is correct
20 Correct 0 ms 4768 KB Output is correct
21 Correct 3 ms 4768 KB Output is correct
22 Correct 76 ms 4768 KB Output is correct
23 Correct 43 ms 4768 KB Output is correct
24 Correct 46 ms 4768 KB Output is correct
25 Correct 46 ms 4768 KB Output is correct
26 Correct 63 ms 4768 KB Output is correct
27 Correct 23 ms 4768 KB Output is correct
28 Correct 36 ms 4768 KB Output is correct
29 Correct 56 ms 4768 KB Output is correct
30 Correct 73 ms 4768 KB Output is correct