답안 #528146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528146 2022-02-19T12:40:06 Z buidangnguyen05 Skyscraper (JOI16_skyscraper) C++14
15 / 100
1 ms 588 KB
/* input

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 110, mod = 1e9 + 7;
int a[N], f[N][N][10 * N][3];

void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	if (fopen("task.inp", "r")) {
		freopen("task.inp", "r", stdin);
		freopen("task.out", "w", stdout);
	}

	int n, mx; cin >> n >> mx;
	for (int i = 1; i <= n; ++i) cin >> a[i];

	sort (a + 1, a + n + 1); a[n + 1] = 1e5;
	f[0][0][0][0] = 1;
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
			for (int k = 1; k <= mx; ++k) for (int m = 0; m < 3; ++m) {
					int diff = (2 * j - m) * (a[i + 1] - a[i]);
					if (diff > k || i + j + 1 - m > n) continue;

					add(f[i][j][k][m], f[i - 1][j - 1][k - diff][m]);
					if (m) add(f[i][j][k][m], 1LL * (3 - m) * f[i - 1][j - 1][k - diff][m - 1] % mod);
					add(f[i][j][k][m], 1LL * (2 * j - m) * f[i - 1][j][k - diff][m] % mod);

					if (m == 1) add(f[i][j][k][m], 2LL * j * f[i - 1][j][k - diff][m - 1] % mod);
					else if (m == 2) {
						if (i == n) add(f[i][j][k][m], f[i - 1][j][k - diff][m - 1]);
						else add(f[i][j][k][m], 1LL * (j - 1) * f[i - 1][j][k - diff][m - 1] % mod);
					}

					if (m == 1) add(f[i][j][k][m], 1LL * j * j * f[i - 1][j + 1][k - diff][m] % mod);
					else if (!m) add(f[i][j][k][m], 1LL * j * (j + 1) * f[i - 1][j + 1][k - diff][m] % mod);
					else {
						if (i == n) add(f[i][j][k][m], f[i - 1][j + 1][k - diff][m]);
						else add(f[i][j][k][m], 1LL * j * (j - 1) * f[i - 1][j + 1][k - diff][m] % mod);
					}
				}
		}

	int res = 0;
	for (int i = 0; i <= mx; ++i) add(res, f[n][1][i][2]);
	cout << res << "\n";
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen("task.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   freopen("task.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -