Submission #590930

# Submission time Handle Problem Language Result Execution time Memory
590930 2022-07-06T14:50:07 Z messiuuuuu Skyscraper (JOI16_skyscraper) C++14
100 / 100
41 ms 15876 KB
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e2 + 5;
const int MAXM = 1e3 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 7;

int n, l, a[MAXN];

void Input()
{
    cin >> n >> l;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
}

int mul(int a, int b)
{
    return 1ll * a * b % MOD;
}

void add(int& a, int b)
{
    a += b;
    if (a > MOD)
        a -= MOD;
}

int dp[MAXN][MAXN][MAXM][3];

void Solve()
{
    sort (a + 1, a + n + 1);
    dp[1][1][0][0] = dp[1][1][0][2] = 1;
    dp[1][1][0][1] = 2;
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            for (int k = 0; k <= l; k++)
            {
                for (int z = 0; z <= 2; z++)
                {
                    int nk = k + (2 * j - z) * (a[i + 1] - a[i]);
                    if (!dp[i][j][k][z] || nk < 0 || nk > l)
                        continue;

                    add(dp[i + 1][j + 1][nk][z], mul(dp[i][j][k][z], j + 1 - z));

                    add(dp[i + 1][j][nk][z], mul(dp[i][j][k][z], 2 * j - z));

                    if (j >= 2)
                        add(dp[i + 1][j - 1][nk][z], mul(dp[i][j][k][z], j - 1));

                    if (z < 2)
                    {
                        add(dp[i + 1][j][nk][z + 1], mul(dp[i][j][k][z], 2 - z));
                        add(dp[i + 1][j + 1][nk][z + 1], mul(dp[i][j][k][z], 2 - z));
                    }
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= l; i++)
        add(ans, dp[n][1][i][2]);
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 39 ms 15876 KB Output is correct
23 Correct 36 ms 6224 KB Output is correct
24 Correct 35 ms 9036 KB Output is correct
25 Correct 39 ms 6912 KB Output is correct
26 Correct 36 ms 6556 KB Output is correct
27 Correct 17 ms 8240 KB Output is correct
28 Correct 27 ms 9700 KB Output is correct
29 Correct 34 ms 12084 KB Output is correct
30 Correct 41 ms 7044 KB Output is correct