Submission #397082

# Submission time Handle Problem Language Result Execution time Memory
397082 2021-05-01T10:20:01 Z hltk Skyscraper (JOI16_skyscraper) C++17
100 / 100
377 ms 158660 KB
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define MAXN 100
#define MAXL 1001
#define MOD 1000000007

int N, L, A[MAXN];
int DP[MAXN][MAXL][2][MAXN + 1][2];

int dp(int i, int l, int kl, int k, int kr) {
	if (i == N - 1) return k == 0;

	int &ret = DP[i][l][kl][k][kr];
	if (ret != -1) return ret;

	auto get = [&](int nkl, int nk, int nkr) {
		if (nk < 0) return 0;
		int nxtl = l + (A[i + 1] - A[i]) * (nkl + nkr + nk * 2);
		return nxtl <= L ? dp(i + 1, nxtl, nkl, nk, nkr) : 0;
	};

	long long lret = 0;

	lret += 1ll * get(kl, k, kr) * k * 2 % MOD;
	lret += get(kl, k + 1, kr);
	lret += 1ll * get(kl, k - 1, kr) * k * (k - 1) % MOD;
	lret += get(1, k, kr);
	lret += get(kl, k, 1);
	lret += 1ll * get(1, k - 1, kr) * k % MOD;
	lret += 1ll * get(kl, k - 1, 1) * k % MOD;

	return ret = (int) (lret % MOD);
}

int main() {
	scanf("%d %d", &N, &L);

	for (int i = 0; i < N; ++i)
		scanf("%d", A + i);

	sort(A, A + N);

	memset(DP, -1, sizeof(DP));

	printf("%d\n", dp(0, 0, 0, 0, 0));
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |  scanf("%d %d", &N, &L);
      |  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 67 ms 158532 KB Output is correct
2 Correct 65 ms 158416 KB Output is correct
3 Correct 65 ms 158524 KB Output is correct
4 Correct 66 ms 158532 KB Output is correct
5 Correct 69 ms 158532 KB Output is correct
6 Correct 65 ms 158432 KB Output is correct
7 Correct 66 ms 158432 KB Output is correct
8 Correct 65 ms 158476 KB Output is correct
9 Correct 65 ms 158532 KB Output is correct
10 Correct 66 ms 158460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 158460 KB Output is correct
2 Correct 73 ms 158452 KB Output is correct
3 Correct 69 ms 158476 KB Output is correct
4 Correct 68 ms 158532 KB Output is correct
5 Correct 71 ms 158464 KB Output is correct
6 Correct 68 ms 158532 KB Output is correct
7 Correct 74 ms 158452 KB Output is correct
8 Correct 68 ms 158432 KB Output is correct
9 Correct 69 ms 158444 KB Output is correct
10 Correct 73 ms 158532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 158532 KB Output is correct
2 Correct 65 ms 158416 KB Output is correct
3 Correct 65 ms 158524 KB Output is correct
4 Correct 66 ms 158532 KB Output is correct
5 Correct 69 ms 158532 KB Output is correct
6 Correct 65 ms 158432 KB Output is correct
7 Correct 66 ms 158432 KB Output is correct
8 Correct 65 ms 158476 KB Output is correct
9 Correct 65 ms 158532 KB Output is correct
10 Correct 66 ms 158460 KB Output is correct
11 Correct 69 ms 158460 KB Output is correct
12 Correct 73 ms 158452 KB Output is correct
13 Correct 69 ms 158476 KB Output is correct
14 Correct 68 ms 158532 KB Output is correct
15 Correct 71 ms 158464 KB Output is correct
16 Correct 68 ms 158532 KB Output is correct
17 Correct 74 ms 158452 KB Output is correct
18 Correct 68 ms 158432 KB Output is correct
19 Correct 69 ms 158444 KB Output is correct
20 Correct 73 ms 158532 KB Output is correct
21 Correct 70 ms 158500 KB Output is correct
22 Correct 377 ms 158544 KB Output is correct
23 Correct 283 ms 158532 KB Output is correct
24 Correct 263 ms 158552 KB Output is correct
25 Correct 287 ms 158472 KB Output is correct
26 Correct 257 ms 158552 KB Output is correct
27 Correct 148 ms 158548 KB Output is correct
28 Correct 166 ms 158548 KB Output is correct
29 Correct 267 ms 158548 KB Output is correct
30 Correct 284 ms 158660 KB Output is correct