답안 #57162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57162 2018-07-14T07:43:10 Z 김세빈(#1653) Skyscraper (JOI16_skyscraper) C++11
15 / 100
5 ms 1024 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

ll D[2][111][3][1010];
ll A[111];
ll n, k, ans;

int main()
{
	ll i, j, l, x, t;
	
	scanf("%lld%lld", &n, &k);
	
	for(i=1;i<=n;i++){
		scanf("%lld", A+i);
	}
	
	sort(A+1, A+n+1);
	
	D[0][0][0][0] = 1;
	
	for(i=1;i<n;i++){
		for(j=0;j<=i;j++){
			for(l=0;l<=k;l++){
				// endpoints
				
				t = l + (A[i] - A[i-1]) * j * 2;
				if(t <= k){
					if(j){
						D[i&1][j-1][1][t] = (D[i&1][j-1][1][t] + D[~i&1][j][0][l] * (ll)2) % mod;
					}
					D[i&1][j][1][t] = (D[i&1][j][1][t] + D[~i&1][j][0][l] * (ll)2) % mod;
				}
				
				t = l + (A[i] - A[i-1]) * (j * 2 + 1);
				if(t <= k){
					if(j){
						D[i&1][j-1][2][t] = (D[i&1][j-1][2][t] + D[~i&1][j][1][l]) % mod;
						D[i&1][j-1][1][t] = (D[i&1][j-1][1][t] + D[~i&1][j][1][l]) % mod;
					}
					D[i&1][j][2][t] = (D[i&1][j][2][t] + D[~i&1][j][1][l]) % mod;
					D[i&1][j][1][t] = (D[i&1][j][1][t] + D[~i&1][j][1][l]) % mod;
				}
				
				t = l + (A[i] - A[i-1]) * (j * 2 + 2);
				if(t <= k){
					if(j){
						D[i&1][j-1][2][t] = (D[i&1][j-1][2][t] + D[~i&1][j][2][l] * (ll)2) % mod;
					}
					D[i&1][j][2][t] = (D[i&1][j][2][t] + D[~i&1][j][2][l] * (ll)2) % mod;
				}
				
				
				for(x=0;x<3;x++){
					t = l + (A[i] - A[i-1]) * (j * 2 + x);
					
					if(t <= k){
						
						// new group
						D[i&1][j+1][x][t] = (D[i&1][j+1][x][t] + D[~i&1][j][x][l] * (ll)(j + 1)) % mod;
						
						// merge two groups
						if(j > 1){
							D[i&1][j-1][x][t] = (D[i&1][j-1][x][t] + D[~i&1][j][x][l] * (ll)(j - 1)) % mod;
						}
						
						// group endpoints
						D[i&1][j][x][t] = (D[i&1][j][x][t] + D[~i&1][j][x][l] * (ll)2 * j) % mod;
					}
					
					D[~i&1][j][x][l] = 0;
				}
			}
		}
	}
	
	for(i=0;i<=k;i++){
		t = i + (A[n] - A[n-1]) * 2;
		if(t <= k) ans = (ans + D[~n&1][0][2][i]) % mod;
		
		t = i + (A[n] - A[n-1]);
		if(t <= k) ans = (ans + D[~n&1][0][1][i]) % mod;
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", A+i);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 868 KB Output is correct
2 Correct 3 ms 868 KB Output is correct
3 Correct 2 ms 868 KB Output is correct
4 Correct 3 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 900 KB Output is correct
7 Correct 4 ms 900 KB Output is correct
8 Correct 5 ms 900 KB Output is correct
9 Correct 4 ms 900 KB Output is correct
10 Correct 4 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -