Submission #159953

# Submission time Handle Problem Language Result Execution time Memory
159953 2019-10-25T14:19:50 Z iefnah06 Skyscraper (JOI16_skyscraper) C++11
100 / 100
61 ms 3192 KB
#include <bits/stdc++.h>
using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;

const uint MOD = 1e9 + 7;

struct num {
	uint v;
	num(uint _v = 0) : v(_v) { }

	num& operator += (const num& r) {
		if ((v += r.v) >= MOD) v -= MOD;
		return *this;
	}
	num& operator *= (const num& r) {
		v = (ull)v * r.v % MOD;
		return *this;
	}

	num operator + (const num& r) const { return num(*this) += r; }
	num operator * (const num& r) const { return num(*this) *= r; }
};

const int MAXN = 110;
const int MAXL = 1010;
int N;
int L;

int A[MAXN];

num dp[MAXN][MAXL][3];
num ndp[MAXN][MAXL][3];

void append(int deltaA) {
	memset(ndp, 0, sizeof(ndp));
	for (int c = 0; c <= N; c++) {
		for (int v = 0; v <= L; v++) {
			for (int t = 0; t <= 2; t++) {
				int nv = v + deltaA * (t + 2 * c);
				if (nv > L || !dp[c][v][t].v) continue;

				// head or tail
				if (t) {
					num ways = dp[c][v][t] * t;
					ndp[c+1][nv][t] += ways;
					ndp[c+1][nv][t-1] += ways;
					ndp[c][nv][t] += ways;
					ndp[c][nv][t-1] += ways;
				}

				// some gap in the middle
				if (c) {
					num ways = dp[c][v][t] * c;
					ndp[c+1][nv][t] += ways;
					ndp[c][nv][t] += ways * 2;
					ndp[c-1][nv][t] += ways;
				}
			}
		}
	}
	memcpy(dp, ndp, sizeof(ndp));
}

int main() {
	scanf("%d %d", &N, &L);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	sort(A, A + N);
	dp[0][0][0] = 1;
	dp[0][0][1] = 2;
	dp[0][0][2] = 1;
	for (int i = 1; i < N; i++) {
		append(A[i] - A[i-1]);
	}

	num ans = 0;
	for (int v = 0; v <= L; v++) {
		ans += dp[0][v][0];
	}
	printf("%u\n", ans.v);

	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:67:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &L);
  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:69:8: 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 5 ms 3192 KB Output is correct
2 Correct 5 ms 2936 KB Output is correct
3 Correct 5 ms 2936 KB Output is correct
4 Correct 6 ms 3064 KB Output is correct
5 Correct 6 ms 3064 KB Output is correct
6 Correct 6 ms 2936 KB Output is correct
7 Correct 6 ms 2936 KB Output is correct
8 Correct 6 ms 2936 KB Output is correct
9 Correct 6 ms 2936 KB Output is correct
10 Correct 6 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3064 KB Output is correct
2 Correct 7 ms 2936 KB Output is correct
3 Correct 7 ms 2936 KB Output is correct
4 Correct 7 ms 2936 KB Output is correct
5 Correct 7 ms 2936 KB Output is correct
6 Correct 7 ms 2936 KB Output is correct
7 Correct 7 ms 2936 KB Output is correct
8 Correct 7 ms 2936 KB Output is correct
9 Correct 7 ms 2936 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3192 KB Output is correct
2 Correct 5 ms 2936 KB Output is correct
3 Correct 5 ms 2936 KB Output is correct
4 Correct 6 ms 3064 KB Output is correct
5 Correct 6 ms 3064 KB Output is correct
6 Correct 6 ms 2936 KB Output is correct
7 Correct 6 ms 2936 KB Output is correct
8 Correct 6 ms 2936 KB Output is correct
9 Correct 6 ms 2936 KB Output is correct
10 Correct 6 ms 2936 KB Output is correct
11 Correct 7 ms 3064 KB Output is correct
12 Correct 7 ms 2936 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Correct 7 ms 2936 KB Output is correct
15 Correct 7 ms 2936 KB Output is correct
16 Correct 7 ms 2936 KB Output is correct
17 Correct 7 ms 2936 KB Output is correct
18 Correct 7 ms 2936 KB Output is correct
19 Correct 7 ms 2936 KB Output is correct
20 Correct 7 ms 2936 KB Output is correct
21 Correct 13 ms 2936 KB Output is correct
22 Correct 53 ms 2936 KB Output is correct
23 Correct 60 ms 2968 KB Output is correct
24 Correct 55 ms 2936 KB Output is correct
25 Correct 61 ms 3064 KB Output is correct
26 Correct 55 ms 3008 KB Output is correct
27 Correct 35 ms 3004 KB Output is correct
28 Correct 40 ms 2936 KB Output is correct
29 Correct 52 ms 2936 KB Output is correct
30 Correct 59 ms 2936 KB Output is correct