이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
unordered_map<ll, ll> 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;
}
ll t=val; t*=101; t+=pos; t*=101; t+=comp; t*=4; t+=state;
if(dp.find(t)!=dp.end()) return dp[t];
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[t]=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++) A[i]-=A[1]-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);
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |