Submission #343225

# Submission time Handle Problem Language Result Execution time Memory
343225 2021-01-03T14:40:26 Z saniyar_krmi Skyscraper (JOI16_skyscraper) C++14
100 / 100
206 ms 39276 KB
// YOt ONLY GOT ONE SHOT
#include <bits/stdc++.h>
#define put(x) cerr << #x << ": " << x << '\n'
#define line() cerr << "**************\n"

//#define F first
//#define S second
//#define mul(x, y) (((x) * (y)) %mod)
//#define bit(i, j) (((i)>>(j)) &1)
//#define left(id) ((id<<1) + 1)
//#define right(id) ((id<<1) + 2)
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

const int maxn = 100 + 10, maxA = 1000 + 10, mod = 1e9 + 7;
int n, l;
int a[maxn];
int dp[maxn][maxn][maxA][3];

ll mul(ll a, ll b){
	return (a * b) %mod;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);  cout.tie(0);

	cin >> n >> l;
	for(int i=0; i<n; i++)
		cin >> a[i];
	sort(a, a+n);

	if(n == 1)
		return cout << "1\n", 0;
	
	for(int i=0; i<=l; i++)
		dp[0][0][i][0] = 1;
	int cost = 0;
	for(int i=1; i<=n; i++)
		for(int j = 1; j <= min(i, (n+1) /2); j++)
			for(int k=0; k<=l; k++)
				for(int m=0; m<3; m++){
					cost = (j * 2 - m) * (a[i] - a[i-1]);
					if(cost > k)
						continue;

					if(m > 0){
						dp[i][j][k][m] += mul(dp[i-1][j][k - cost][m-1], 3 - m);
						dp[i][j][k][m] %= mod;
						if(i + j + 1 - m <= n){
							dp[i][j][k][m] += mul(dp[i-1][j-1][k - cost][m-1], 3 - m);
							dp[i][j][k][m] %= mod;
						}
					}
					if(i + j +1 - m <= n){
						dp[i][j][k][m] += mul(dp[i-1][j-1][k - cost][m], j - m);
						dp[i][j][k][m] %= mod;
						dp[i][j][k][m] += mul(dp[i-1][j][k - cost][m], j * 2 - m);
						dp[i][j][k][m] %= mod;
					}
					if(j < (n + 1) /2){
						dp[i][j][k][m] += mul(dp[i-1][j+1][k - cost][m], j) %mod;
						dp[i][j][k][m] %= mod;
					}
				}

	cout << dp[n][1][l][2] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 640 KB Output is correct
21 Correct 4 ms 3052 KB Output is correct
22 Correct 135 ms 27884 KB Output is correct
23 Correct 187 ms 36992 KB Output is correct
24 Correct 173 ms 39276 KB Output is correct
25 Correct 206 ms 37612 KB Output is correct
26 Correct 172 ms 36332 KB Output is correct
27 Correct 74 ms 24556 KB Output is correct
28 Correct 86 ms 27116 KB Output is correct
29 Correct 148 ms 37356 KB Output is correct
30 Correct 199 ms 37868 KB Output is correct