Submission #631103

# Submission time Handle Problem Language Result Execution time Memory
631103 2022-08-17T17:07:15 Z urosk Skyscraper (JOI16_skyscraper) C++14
20 / 100
2000 ms 269980 KB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}

typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}
#define maxn 105
ll n,L;
ll a[maxn];
map<ll,ll> dp[maxn][maxn][2][2];

int main(){
	daj_mi_malo_vremena
    cin >> n >> L;
    for(ll i = 1;i<=n;i++) cin >> a[i];
    if(n==1){cout<<1<<endl;return 0;}
    sort(a+1,a+n+1);
    dp[1][1][1][0][-a[1]] = 1;
    dp[1][1][0][1][-a[1]] = 1;
    dp[1][1][0][0][-2*a[1]] = 1;
	for(ll i = 2;i<=n;i++){
        for(ll j = 1;j<=n;j++){
            for(ll l = 0;l<=1;l++){
                for(ll r = 0;r<=1;r++){
                    for(pll p : dp[i-1][j][l][r]){
                        ll k = p.fi;
                        ll cnt = p.sc;
                        if(k>L) break;
                        dp[i][j][l][r][k] = add(dp[i][j][l][r][k],mul(cnt,2*j-l-r));
                        if(!l) dp[i][j][1][r][k+a[i]] = add(dp[i][j][1][r][k+a[i]],cnt);
                        if(!r) dp[i][j][l][1][k+a[i]] = add(dp[i][j][l][1][k+a[i]],cnt);
                        dp[i][j+1][l][r][k-2*a[i]] = add(dp[i][j+1][l][r][k-2*a[i]],mul(cnt,j+1-l-r));
                        if(!l) dp[i][j+1][1][r][k-a[i]] = add(dp[i][j+1][1][r][k-a[i]],cnt);
                        if(!r) dp[i][j+1][l][1][k-a[i]] = add(dp[i][j+1][l][1][k-a[i]],cnt);
                        dp[i][j-1][l][r][k+2*a[i]] = add(dp[i][j-1][l][r][k+2*a[i]],mul(cnt,j-1));
                    }
                }
            }
        }
	}
	ll ans = 0;
	for(pll p : dp[n][1][1][1]){
        ll k = p.fi;
        ll cnt = p.sc;
        if(k<=L) ans = add(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 2 ms 2528 KB Output is correct
5 Correct 7 ms 4052 KB Output is correct
6 Correct 8 ms 4180 KB Output is correct
7 Correct 6 ms 3368 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 8 ms 4192 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3040 KB Output is correct
2 Correct 43 ms 8832 KB Output is correct
3 Correct 9 ms 3804 KB Output is correct
4 Correct 39 ms 8940 KB Output is correct
5 Correct 59 ms 10064 KB Output is correct
6 Correct 25 ms 6472 KB Output is correct
7 Correct 14 ms 4700 KB Output is correct
8 Correct 9 ms 3796 KB Output is correct
9 Correct 10 ms 3888 KB Output is correct
10 Correct 33 ms 7860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 2 ms 2528 KB Output is correct
5 Correct 7 ms 4052 KB Output is correct
6 Correct 8 ms 4180 KB Output is correct
7 Correct 6 ms 3368 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 8 ms 4192 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 5 ms 3040 KB Output is correct
12 Correct 43 ms 8832 KB Output is correct
13 Correct 9 ms 3804 KB Output is correct
14 Correct 39 ms 8940 KB Output is correct
15 Correct 59 ms 10064 KB Output is correct
16 Correct 25 ms 6472 KB Output is correct
17 Correct 14 ms 4700 KB Output is correct
18 Correct 9 ms 3796 KB Output is correct
19 Correct 10 ms 3888 KB Output is correct
20 Correct 33 ms 7860 KB Output is correct
21 Correct 492 ms 64468 KB Output is correct
22 Execution timed out 2094 ms 269980 KB Time limit exceeded
23 Halted 0 ms 0 KB -