답안 #362802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362802 2021-02-04T11:54:42 Z QCFium Skyscraper (JOI16_skyscraper) C++14
100 / 100
321 ms 3564 KB
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MOD 1000000007

int main() {
	int n = ri();
	
	// !!!! corner case n <= 2  !!!!
	
	int l = ri();
	int a[n];
	for (auto &i : a) i = ri();
	
	std::sort(a, a + n);
	
	int dp[l + 1][n][2][2];
	memset(dp, 0, sizeof(dp));
	
	auto add = [&] (int &a, int b) {
		a += b;
		if (a >= MOD) a -= MOD;
	};
	
	for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) dp[0][0][i][j] = 1;
	for (int i = 1; i < n; i++) {
		int len = a[i] - a[i - 1];
		
		int tmp[l + 1][n][2][2];
		memset(tmp, 0, sizeof(tmp));
		for (int j = 0; j <= l; j++) for (int k = 0; k < n; k++)
			for (int p = 0; p < 2; p++) for (int q = 0; q < 2; q++)
				if (j + (k + p + q) * len <= l && (k + k + p + q)) add(tmp[j + (k + k + p + q) * len][k][p][q], dp[j][k][p][q]);
		memset(dp, 0, sizeof(dp));
		
		for (int j = 0; j <= l; j++) {
			for (int k = 0; k < n; k++) {
				for (int p = 0; p < 2; p++) {
					for (int q = 0; q < 2; q++) {
						if (!tmp[j][k][p][q]) continue;
						// fprintf(stderr, "at %d, used : %d, (%d, %d, %d) : %d\n", i, j, p, k, q, tmp[j][k][p][q]);
						if (p) {
							add(dp[j][k][0][q], tmp[j][k][p][q]);
							add(dp[j][k][p][q], tmp[j][k][p][q]);
							add(dp[j][k + 1][0][q], tmp[j][k][p][q]);
							add(dp[j][k + 1][p][q], tmp[j][k][p][q]);
						}
						if (q) {
							add(dp[j][k][p][0], tmp[j][k][p][q]);
							add(dp[j][k][p][q], tmp[j][k][p][q]);
							add(dp[j][k + 1][p][0], tmp[j][k][p][q]);
							add(dp[j][k + 1][p][q], tmp[j][k][p][q]);
						}
						if (k) {
							add(dp[j][k - 1][p][q], (int64_t) tmp[j][k][p][q] * k % MOD);
							add(dp[j][k][p][q], (int64_t) tmp[j][k][p][q] * k % MOD);
							add(dp[j][k][p][q], (int64_t) tmp[j][k][p][q] * k % MOD);
							add(dp[j][k + 1][p][q], (int64_t) tmp[j][k][p][q] * k % MOD);
						}
					}
				}
			}
		}
	}
	
	int res = 0;
	for (int i = 0; i <= l; i++) add(res, dp[i][0][0][0]);
	printf("%d\n", res);
	
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int ri()':
skyscraper.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    5 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 208 ms 2284 KB Output is correct
23 Correct 313 ms 3436 KB Output is correct
24 Correct 248 ms 2668 KB Output is correct
25 Correct 315 ms 3564 KB Output is correct
26 Correct 271 ms 3052 KB Output is correct
27 Correct 93 ms 1132 KB Output is correct
28 Correct 108 ms 1260 KB Output is correct
29 Correct 207 ms 2156 KB Output is correct
30 Correct 321 ms 3436 KB Output is correct