Submission #442761

# Submission time Handle Problem Language Result Execution time Memory
442761 2021-07-09T00:17:37 Z Bench0310 Skyscraper (JOI16_skyscraper) C++17
100 / 100
594 ms 5364 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const ll mod=1000000007;
    auto add=[&](ll a,ll b)->ll{return (a+b)%mod;};
    auto madd=[&](ll &a,ll b){a=add(a,b);};
    auto mul=[&](ll a,ll b)->ll{return (a*b)%mod;};
    int n,l;
    cin >> n >> l;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    a.push_back(0);
    vector dp(n+1,vector(l+1,array<ll,3>{0,0,0}));
    dp[0][0][0]=1;
    auto c=[&](int i,int e,int x)->int{return (2*i-e)*x;};
    for(int o=0;o<n;o++)
    {
        vector ndp(n+1,vector(l+1,array<ll,3>{0,0,0}));
        auto upd=[&](int i,int j,int e,ll val)
        {
            j+=c(i,e,a[o+1]);
            if(1<=i&&i<=n&&0<=j&&j<=l&&0<=e&&e<=2) madd(ndp[i][j][e],val);
        };
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=l;j++)
            {
                for(int e=0;e<=2;e++)
                {
                    int nj=j-c(i,e,a[o]);
                    //create a new group
                    upd(i+1,nj-2*a[o],e,mul(i+1-e,dp[i][j][e]));
                    //create a new group as an end
                    upd(i+1,nj-a[o],e+1,mul(2-e,dp[i][j][e]));
                    //add to a group
                    upd(i,nj,e,mul(2*i-e,dp[i][j][e]));
                    //add to a group as an end
                    upd(i,nj+a[o],e+1,mul(2-e,dp[i][j][e]));
                    //merge two groups
                    if(i>=2) upd(i-1,nj+2*a[o],e,mul(i-1,dp[i][j][e]));
                }
            }
        }
        dp=ndp;
    }
    ll res=(n==1);
    for(int j=0;j<=l;j++) madd(res,dp[1][j][2]);
    cout << res << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 4 ms 668 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 4 ms 668 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 5 ms 332 KB Output is correct
22 Correct 452 ms 3540 KB Output is correct
23 Correct 565 ms 5364 KB Output is correct
24 Correct 481 ms 3872 KB Output is correct
25 Correct 594 ms 5064 KB Output is correct
26 Correct 490 ms 4444 KB Output is correct
27 Correct 165 ms 1552 KB Output is correct
28 Correct 220 ms 1864 KB Output is correct
29 Correct 433 ms 3080 KB Output is correct
30 Correct 587 ms 5356 KB Output is correct