답안 #479378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479378 2021-10-11T14:19:49 Z 8e7 Skyscraper (JOI16_skyscraper) C++17
100 / 100
212 ms 2696 KB
//Challenge: Accepted
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <assert.h>
#include <iomanip>
using namespace std;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
	while (l != r) {cout << *l << " ";l++;}
	cout << endl;
}
#define ll long long
#define maxn 105
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int dp[2][3][maxn][1005];
int a[maxn];
void madd(int &x, int v) {
	x += v - mod, x += mod & (x>>31);
}
int main() {
	int n, l;
	cin >> n >> l;
	for (int i = 0;i < n;i++) cin >> a[i];
	sort(a, a + n, [&](int x, int y){return x > y;});
	dp[0][0][0][0] = 1, dp[0][1][1][0] = 2, dp[0][2][2][0] = 1;
	for (int i = 0;i < n-1;i++) {
		int dif = a[i] - a[i+1];
		for (int c = 0;c < 3;c++) {
			for (int j = 1;j <= n;j++) {
				for (int k = 0;k <= l;k++) {
					int cost = k + (j-c) * 2 * dif + c * dif;
					if (cost > l) continue;
					//takes a gap in middle
					madd(dp[1][c][j-1][cost], (ll)dp[0][c][j][k] * (j - c) % mod);
					madd(dp[1][c][j][cost], (ll)dp[0][c][j][k] * (2 * (j-c) + c)% mod);
					madd(dp[1][c][j+1][cost], (ll)dp[0][c][j][k] * j % mod);
					//removes one of the sides
					if (c) {
						madd(dp[1][c-1][j-1][cost], (ll)dp[0][c][j][k] * c % mod);
						madd(dp[1][c-1][j][cost], (ll)dp[0][c][j][k] * c % mod);
					}
				}
			}
		}	
		for (int c = 0;c < 3;c++) {
			for (int j = 0;j <= n;j++) {
				for (int k = 0;k <= l;k++) dp[0][c][j][k] = dp[1][c][j][k], dp[1][c][j][k] = 0;
			}
		}	
		
	}
	int ans = 0;
	for (int i = 0;i <= l;i++) madd(ans, dp[0][0][0][i]);
	cout << ans << endl;
}
/*
 *
8 35
3 7 1 5 10 2 11 6
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 556 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 672 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 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 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 556 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 672 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 2 ms 1228 KB Output is correct
22 Correct 154 ms 2124 KB Output is correct
23 Correct 169 ms 2696 KB Output is correct
24 Correct 161 ms 2696 KB Output is correct
25 Correct 212 ms 2696 KB Output is correct
26 Correct 146 ms 2648 KB Output is correct
27 Correct 57 ms 2680 KB Output is correct
28 Correct 77 ms 2636 KB Output is correct
29 Correct 150 ms 2608 KB Output is correct
30 Correct 174 ms 2636 KB Output is correct