(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #1079362

#TimeUsernameProblemLanguageResultExecution timeMemory
1079362alexander707070Skyscraper (JOI16_skyscraper)C++14
20 / 100
2082 ms258128 KiB
#include<bits/stdc++.h> #define MAXN 107 using namespace std; const long long mod=1e9+7; int n,s,a[MAXN],ans; unordered_map<int,int> dp[MAXN][MAXN][3][3]; bool ok(int sum){ return sum>=-5000 and sum<=s; } long long even(int pos,int bal,int sum,int l,int r){ if(bal<0 or bal>n or sum>s)return 0; long long free=2*(bal-n/2)+(-(l==1)-(r==1)) - (-(l==2)-(r==2)); if(free<0)return 0; if(pos==n+1 and bal==n/2 and l+r==3 and free==0)return 1; else if(pos==n+1 and (bal==n/2-1 or bal==n/2+1) and l==r and l!=0 and free==0)return 1; else if(pos==n+1)return 0; if(free==0 and pos!=1)return 0; if(ok(sum) and dp[pos][bal][l][r].find(sum)!=dp[pos][bal][l][r].end())return dp[pos][bal][l][r][sum]; long long curr=0; curr+=even(pos+1,bal,sum,l,r)*free; if(l==0){ curr+=even(pos+1,bal+1,sum-a[pos],1,r); curr+=even(pos+1,bal-1,sum+a[pos],2,r); } if(r==0){ curr+=even(pos+1,bal+1,sum-a[pos],l,1); curr+=even(pos+1,bal-1,sum+a[pos],l,2); } long long mult=bal-n/2+1-(l==1)-(r==1); long long mult2=bal-n/2-1+(l==2)+(r==2); curr+=even(pos+1,bal+1,sum-2*a[pos],l,r)*mult; curr+=even(pos+1,bal-1,sum+2*a[pos],l,r)*mult2; curr%=mod; if(ok(sum))dp[pos][bal][l][r][sum]=curr; return curr; } void calc_even(){ ans+=even(1,n/2,0,0,0); } int main(){ cin>>n>>s; int mins=1000; if(n==1){ cout<<1<<"\n"; return 0; } for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+n+1); mins=a[1]; for(int i=1;i<=n;i++){ a[i]-=mins; } calc_even(); cout<<ans%mod<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...