Submission #1029362

# Submission time Handle Problem Language Result Execution time Memory
1029362 2024-07-20T18:53:11 Z codefox Skyscraper (JOI16_skyscraper) C++14
100 / 100
205 ms 16988 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")

#define int long long
const int mod = 1e9 + 7;

int32_t main()
{
    int n, l;
    cin >> n >> l;
    if (n==1)
    {
        cout << 1;
        return 0;
    }
    vector<int> nums(n);
    for (int i = 0; i < n; i++)
    {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end());
    vector<vector<vector<vector<int>>>> dp(2, vector<vector<vector<int>>>(l+1, vector<vector<int>>(n+1, vector<int>(3, 0))));
    dp[1][0][1][0] = 1;
    dp[1][0][1][1] = 2;
    for (int i = 1; i < n; i++)
    {
        int ii = (i+1)%2;
        int cc = (i)%2;
        dp[ii].assign(l+1, vector<vector<int>>(n+1, vector<int>(3, 0)));
        for (int j = 0; j <= l; j++)
        {
            for (int k = 1; k <= i; k++)
            {
                for (int m =0; m < 3; m++)
                {
                    int nsum = j;
                    nsum = j+(k*2-m)*(nums[i]-nums[i-1]);
                    if(nsum > l) continue;
                    dp[ii][nsum][k][m] += dp[cc][j][k][m]*(k*2-m);
                    dp[ii][nsum][k-1][m] += dp[cc][j][k][m]*(k-1);
                    dp[ii][nsum][k+1][m] += dp[cc][j][k][m]*(k+1-m);
                    if(m!=2)
                    {
                        dp[ii][nsum][k+1][m+1] += dp[cc][j][k][m]*(2-m);
                        if(k) dp[ii][nsum][k][m+1] += dp[cc][j][k][m]*(2-m);
                        dp[ii][nsum][k+1][m+1]%=mod;
                        dp[ii][nsum][k][m+1]%=mod;
                    }
                    dp[ii][nsum][k][m]%=mod;
                    dp[ii][nsum][k-1][m]%=mod;
                    dp[ii][nsum][k+1][m]%=mod;
                }
            }
        }
    }
    int sum = 0;
    for (int i = 0; i <= l; i++)
    {
        sum += dp[n%2][i][1][2];
        sum%=mod;
    }
    cout << sum;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 1884 KB Output is correct
6 Correct 2 ms 1772 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 1628 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 1884 KB Output is correct
6 Correct 2 ms 1772 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 1628 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 109 ms 11044 KB Output is correct
23 Correct 173 ms 16732 KB Output is correct
24 Correct 131 ms 12636 KB Output is correct
25 Correct 205 ms 16984 KB Output is correct
26 Correct 139 ms 14424 KB Output is correct
27 Correct 49 ms 4440 KB Output is correct
28 Correct 50 ms 5460 KB Output is correct
29 Correct 98 ms 9820 KB Output is correct
30 Correct 153 ms 16988 KB Output is correct