Submission #308912

#TimeUsernameProblemLanguageResultExecution timeMemory
308912arnold518Skyscraper (JOI16_skyscraper)C++14
100 / 100
409 ms383116 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][1010][4]; ll solve(int pos, int comp, int val, int state) { int t=A[pos]-A[pos-1]; val+=(comp*2-state)*t; if(val<0) return 0; if(val>L) return 0; if(pos==N+1) { if(comp==1 && state==2) return 1; else return 0; } ll &ret=dp[pos][comp][val][state]; if(ret!=-1) return ret; ret=0; ret+=(comp+1-state)*solve(pos+1, comp+1, val, state); if(comp>=1) ret+=(comp*2-state)*solve(pos+1, comp, val, state); if(comp>=2) ret+=(comp-1)*solve(pos+1, comp-1, val, state); if(state==1) { ret+=solve(pos+1, comp, val, state+1); ret+=solve(pos+1, comp+1, val, state+1); } else if(state==0) { ret+=2*solve(pos+1, comp, val, state+1); ret+=2*solve(pos+1, comp+1, val, state+1); } ret%=MOD; //printf("%d %d %d %d : %lld\n", 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); A[0]=A[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:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |  scanf("%d%d", &N, &L);
      |  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:54:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |  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...