Submission #28149

# Submission time Handle Problem Language Result Execution time Memory
28149 2017-07-15T13:21:31 Z RayaBurong25_1 Skyscraper (JOI16_skyscraper) C++14
100 / 100
219 ms 260808 KB
//cr zscoder
#include <stdio.h>
#include <algorithm>
#define MOD 1000000007
int A[105];
long long DP[105][105][1005][3];
//i: position of interest
//j: number of connected components
//k: sum of difference in heights
//l: ends filled (0, 1, 2)
//Assume: The unfilled positions for each i is A[i]
int main()
{
	int N, L;
	// freopen("test.in", "r", stdin);
	// freopen("test.out", "w", stdout);
	scanf("%d %d", &N, &L);
	if (N == 1)
	{
		printf("1");
		return 0;
	}
	int i, j, k, l;
	int nk;
	long long f, g;
	for (i = 1; i <= N; i++)
		scanf("%d", &A[i]);
	std::sort(&A[1], &A[N + 1]);
	DP[1][1][0][0] = 1;
	DP[1][1][0][1] = 2;
	for (i = 1; i < N; i++)
	{
		for (j = 1; j <= i; j++)
		{
			for (k = 0; k <= L; k++)
			{
				for (l = 0; l <= 2; l++)
				{
					// printf("%d %d %d %d : %lld\n", i, j, k, l, DP[i][j][k][l]);
					nk = k + (A[i + 1] - A[i])*(2*j - l);
					if (nk > L)
						continue;
					//new component at one end
					if (i + 1 < N)
					{
						if (l < 2)
						{
							f = 2 - l;
							DP[i + 1][j + 1][nk][l + 1] = (DP[i + 1][j + 1][nk][l + 1] + DP[i][j][k][l]*f)%MOD;
						}
						//new component at other places
						DP[i + 1][j + 1][nk][l] = (DP[i + 1][j + 1][nk][l] + DP[i][j][k][l])%MOD;
					}
					//(i + 1)-[end component] or [end component]-(i + 1)
					//becomes whole sequence
					if (i + 1 == N && l == 1)
					{
						DP[i + 1][j][nk][l + 1] = (DP[i + 1][j][nk][l] + DP[i][j][k][l])%MOD;
					}
					//doesn't become whole sequence
					if (i + 1 < N && l >= 1)
					{
						f = l;
						DP[i + 1][j][nk][l] = (DP[i + 1][j][nk][l] + DP[i][j][k][l]*f)%MOD;
					}
					//(i + 1)-[free component] or [free component]-(i + 1)
					//becomes new end
					if (i + 1 < N && l < 2)
					{
						f = (j - l)*(2 - l);
						DP[i + 1][j][nk][l + 1] = (DP[i + 1][j][nk][l + 1] + DP[i][j][k][l]*f)%MOD;
					}
					//doesn't become new end
					if (i + 1 < N)
					{
						f = (j - l)*2;
						DP[i + 1][j][nk][l] = (DP[i + 1][j][nk][l] + DP[i][j][k][l]*f)%MOD;
					}
					//[end component]-(i + 1)-[end component]
					if (i + 1 == N && l == 2)
					{
						DP[i + 1][j - 1][nk][l] = (DP[i + 1][j - 1][nk][l] + DP[i][j][k][l])%MOD;
					}
					//[end component]-(i + 1)-[free component] or [free component]-(i + 1)-[end component]
					if (i + 1 < N && l >= 1)
					{
						f = l*(j - l);
						DP[i + 1][j - 1][nk][l] = (DP[i + 1][j - 1][nk][l] + DP[i][j][k][l]*f)%MOD;
					}
					//[free component]-(i + 1)-[free component]
					if (i + 1 < N && j - l > 1)
					{
						f = (j - l)*(j - l - 1);
						DP[i + 1][j - 1][nk][l] = (DP[i + 1][j - 1][nk][l] + DP[i][j][k][l]*f)%MOD;
					}
				}
			}
		}
	}
	long long Ans = 0;
	for (i = 0; i <= L; i++)
		Ans = (Ans + DP[N][1][i][2])%MOD;
	printf("%lld", Ans);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:25:15: warning: unused variable 'g' [-Wunused-variable]
  long long f, g;
               ^
skyscraper.cpp:17:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &L);
                        ^
skyscraper.cpp:27:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &A[i]);
                     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 260808 KB Output is correct
2 Correct 0 ms 260808 KB Output is correct
3 Correct 0 ms 260808 KB Output is correct
4 Correct 0 ms 260808 KB Output is correct
5 Correct 0 ms 260808 KB Output is correct
6 Correct 0 ms 260808 KB Output is correct
7 Correct 0 ms 260808 KB Output is correct
8 Correct 0 ms 260808 KB Output is correct
9 Correct 0 ms 260808 KB Output is correct
10 Correct 0 ms 260808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 260808 KB Output is correct
2 Correct 0 ms 260808 KB Output is correct
3 Correct 0 ms 260808 KB Output is correct
4 Correct 0 ms 260808 KB Output is correct
5 Correct 0 ms 260808 KB Output is correct
6 Correct 0 ms 260808 KB Output is correct
7 Correct 0 ms 260808 KB Output is correct
8 Correct 0 ms 260808 KB Output is correct
9 Correct 0 ms 260808 KB Output is correct
10 Correct 0 ms 260808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 260808 KB Output is correct
2 Correct 0 ms 260808 KB Output is correct
3 Correct 0 ms 260808 KB Output is correct
4 Correct 0 ms 260808 KB Output is correct
5 Correct 0 ms 260808 KB Output is correct
6 Correct 0 ms 260808 KB Output is correct
7 Correct 0 ms 260808 KB Output is correct
8 Correct 0 ms 260808 KB Output is correct
9 Correct 0 ms 260808 KB Output is correct
10 Correct 0 ms 260808 KB Output is correct
11 Correct 0 ms 260808 KB Output is correct
12 Correct 0 ms 260808 KB Output is correct
13 Correct 0 ms 260808 KB Output is correct
14 Correct 0 ms 260808 KB Output is correct
15 Correct 0 ms 260808 KB Output is correct
16 Correct 0 ms 260808 KB Output is correct
17 Correct 0 ms 260808 KB Output is correct
18 Correct 0 ms 260808 KB Output is correct
19 Correct 0 ms 260808 KB Output is correct
20 Correct 0 ms 260808 KB Output is correct
21 Correct 0 ms 260808 KB Output is correct
22 Correct 166 ms 260808 KB Output is correct
23 Correct 219 ms 260808 KB Output is correct
24 Correct 206 ms 260808 KB Output is correct
25 Correct 209 ms 260808 KB Output is correct
26 Correct 203 ms 260808 KB Output is correct
27 Correct 79 ms 260808 KB Output is correct
28 Correct 103 ms 260808 KB Output is correct
29 Correct 136 ms 260808 KB Output is correct
30 Correct 199 ms 260808 KB Output is correct