답안 #308912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308912 2020-10-02T08:43:24 Z arnold518 Skyscraper (JOI16_skyscraper) C++14
100 / 100
409 ms 383116 KB
#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

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]);
      |                          ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 217 ms 382968 KB Output is correct
3 Correct 219 ms 382968 KB Output is correct
4 Correct 221 ms 382972 KB Output is correct
5 Correct 218 ms 382968 KB Output is correct
6 Correct 218 ms 382968 KB Output is correct
7 Correct 222 ms 382968 KB Output is correct
8 Correct 220 ms 382968 KB Output is correct
9 Correct 214 ms 382968 KB Output is correct
10 Correct 219 ms 382968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 382968 KB Output is correct
2 Correct 219 ms 383096 KB Output is correct
3 Correct 221 ms 383008 KB Output is correct
4 Correct 219 ms 382968 KB Output is correct
5 Correct 217 ms 383096 KB Output is correct
6 Correct 220 ms 382968 KB Output is correct
7 Correct 220 ms 382968 KB Output is correct
8 Correct 220 ms 383056 KB Output is correct
9 Correct 217 ms 382968 KB Output is correct
10 Correct 215 ms 382968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 217 ms 382968 KB Output is correct
3 Correct 219 ms 382968 KB Output is correct
4 Correct 221 ms 382972 KB Output is correct
5 Correct 218 ms 382968 KB Output is correct
6 Correct 218 ms 382968 KB Output is correct
7 Correct 222 ms 382968 KB Output is correct
8 Correct 220 ms 382968 KB Output is correct
9 Correct 214 ms 382968 KB Output is correct
10 Correct 219 ms 382968 KB Output is correct
11 Correct 217 ms 382968 KB Output is correct
12 Correct 219 ms 383096 KB Output is correct
13 Correct 221 ms 383008 KB Output is correct
14 Correct 219 ms 382968 KB Output is correct
15 Correct 217 ms 383096 KB Output is correct
16 Correct 220 ms 382968 KB Output is correct
17 Correct 220 ms 382968 KB Output is correct
18 Correct 220 ms 383056 KB Output is correct
19 Correct 217 ms 382968 KB Output is correct
20 Correct 215 ms 382968 KB Output is correct
21 Correct 219 ms 382968 KB Output is correct
22 Correct 409 ms 383096 KB Output is correct
23 Correct 293 ms 383096 KB Output is correct
24 Correct 312 ms 383096 KB Output is correct
25 Correct 303 ms 383000 KB Output is correct
26 Correct 302 ms 382968 KB Output is correct
27 Correct 261 ms 383116 KB Output is correct
28 Correct 273 ms 383096 KB Output is correct
29 Correct 344 ms 382968 KB Output is correct
30 Correct 296 ms 382968 KB Output is correct