제출 #1222187

#제출 시각아이디문제언어결과실행 시간메모리
1222187minggaSkyscraper (JOI16_skyscraper)C++20
15 / 100
1 ms836 KiB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 105;
int n, l;
int a[N];
int dp[105][105][1005][3];


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

int mul(int x, int y) {
	x %= mod, y %= mod;
	return (x * y) % mod;
}

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n >> l;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	dp[0][0][0][0] = 1;
	a[n + 1] = 100000;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= i; j++) {
			for(int k = 0; k <= l; k++) {
				for(int m = 0; m < 3; m++) {
					int cost = (2 * j - m) * (a[i + 1] - a[i]);
					if(cost > k or i + j + 1 - m > n) continue;
					dp[i][j][k][m] = add(dp[i][j][k][m], dp[i - 1][j - 1][k - cost][m]);
					dp[i][j][k][m] = add(dp[i][j][k][m], mul(2 * j - m, dp[i - 1][j][k - cost][m]));
					if(m > 0) {
						dp[i][j][k][m] = add(dp[i][j][k][m], mul(dp[i - 1][j - 1][k - cost][m - 1], 3 - m));
						if(m == 1) {
							dp[i][j][k][m] = add(dp[i][j][k][m], mul(2 * j, dp[i - 1][j][k - cost][m - 1]));
							dp[i][j][k][m] = add(dp[i][j][k][m], mul(j * j, dp[i - 1][j + 1][k - cost][m]));
						} else {
							if(i == n) dp[i][j][k][m] = add(dp[i][j][k][m], dp[i - 1][j][k - cost][m - 1]);
							else if(j > 1) dp[i][j][k][m] = add(dp[i][j][k][m], mul(j - 1, dp[i - 1][j][k - cost][m - 1]));
							if(i == n) {
								dp[i][j][k][m] = add(dp[i][j][k][m], dp[i - 1][j + 1][k - cost][m]);
							} else {
								dp[i][j][k][m] = add(dp[i][j][k][m], mul(j * (j - 1), dp[i - 1][j + 1][k - cost][m]));
							}
						}
					} else {
						dp[i][j][k][m] = add(dp[i][j][k][m], mul(j * (j + 1), dp[i - 1][j + 1][k - cost][m]));
					}
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0; i <= l; i++) {
		ans = add(ans, dp[n][1][i][2]);
	}
	cout << ans << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:35:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:36:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...