Submission #308898

#TimeUsernameProblemLanguageResultExecution timeMemory
308898arnold518Skyscraper (JOI16_skyscraper)C++14
20 / 100
2045 ms62584 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 100; const ll MOD = 1e9+7; int N, L, A[MAXN+10], S[MAXN+10]; //ll dp[110][110][5000][4]; map<tuple<int, int, int, int>, int> dp; int v1, v2; ll solve(int pos, int comp, int val, int state) { if(val>L) return 0; if(val+S[pos]*2<0) return 0; v1=min(v1, val); v2=max(v2, val); if(pos==N+1) { if(comp==1 && 0<=val && state==3) return 1; else return 0; } if(dp.find({pos, comp, val, state})!=dp.end()) return dp[{pos, comp, val, state}]; ll ret=0; ret=0; int sz=__builtin_popcount(state); ret+=(comp+1-sz)*solve(pos+1, comp+1, val-2*A[pos], state); ret+=(comp*2-sz)*solve(pos+1, comp, val, state); if(comp) ret+=(comp-1)*solve(pos+1, comp-1, val+2*A[pos], state); if((state&1)==0) ret+=solve(pos+1, comp, val+A[pos], state|1); if((state&1)==0) ret+=solve(pos+1, comp+1, val-A[pos], state|1); if((state&2)==0) ret+=solve(pos+1, comp, val+A[pos], state|2); if((state&2)==0) ret+=solve(pos+1, comp+1, val-A[pos], state|2); //printf("%d %d %d %d : %lld\n", pos, comp, val, state, ret); ret%=MOD; dp[{pos, comp, val, state}]=ret; return ret; } int main() { scanf("%d%d", &N, &L); if(N==1) return !printf("1"); for(int i=1; i<=N; i++) scanf("%d", &A[i]); sort(A+1, A+N+1); for(int i=1; i<=N; i++) S[i]=A[i]; for(int i=N; i>=1; i--) S[i]+=S[i+1]; //memset(dp, -1, sizeof(dp)); printf("%lld\n", solve(1, 0, 0, 0)); //printf("!%d %d\n", v1, v2); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |  scanf("%d%d", &N, &L);
      |  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:52:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |  for(int i=1; i<=N; i++) scanf("%d", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...