답안 #290656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290656 2020-09-04T09:34:18 Z Berted Skyscraper (JOI16_skyscraper) C++14
20 / 100
1937 ms 14664 KB
#include <iostream>
#include <algorithm>
#define ll long long
const int MD = 1e9 + 7, C = 5000;
using namespace std;

int n, l, ar[101], dp[2][101][C + 1001][3];

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> l;
	if (n == 1) {cout << "1\n"; return 0;}
	for (int i = 0; i < n; i++) {cin >> ar[i];}
	sort(ar, ar + n);
	dp[0][0][C][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			for (int k = 0; k <= C + l; k++)
			{
				for (int m = 0; m <= 2; m++)
				{
					
					dp[i & 1][j][k][m] = 0;
					if (k + 2 * ar[i - 1] <= C + l && (j > 1 || i == 1)) 
					{
						dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)(j - m) * dp[~i & 1][j - 1][k + 2 * ar[i - 1]][m]) % MD;
					}
					
					if (j < i) 
					{
						dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)(2 * j - m) * dp[~i & 1][j][k][m]) % MD; 
					}
					
					if (k - 2 * ar[i - 1] >= 0 && j + 1 < i && (j >= m || i == n)) 
					{
						dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)j * dp[~i & 1][j + 1][k - 2 * ar[i - 1]][m]) % MD;
					}
					
					if ((j > 1 || i == 1) && k + ar[i - 1] <= C + l && m) {dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)(3 - m) * dp[~i & 1][j - 1][k + ar[i - 1]][m - 1]) % MD;}
					if (k - ar[i - 1] >= 0 && m && (j >= m || i == n) && j < i) {dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)(3 - m) * dp[~i & 1][j][k - ar[i - 1]][m - 1]) % MD;}
					/*
					if (k - C >= -20 && dp[i & 1][j][k][m]) 
					{
						//if (k + 2 * ar[i - 1] <= C + l && (j > 1 || i == 1)) {cout << "New CC : " << i - 1 << " " << j - 1 << " " << k + 2 * ar[i - 1] - C << " " << m << "\n";}
						//if (j < i) cout << "Con 2CC : " << i - 1 << " " << j << " " << k - C << " " << m << "\n";
						//if (k - 2 * ar[i - 1] >= 0 && j + 1 < i && (j >= m || i == n)) {cout << "Merge CC : " << i - 1 << " " << j + 1 << " " << k - 2 * ar[i - 1] - C << " " << m << "\n";}
						//if (j && k + ar[i - 1] <= C + l && m) {cout << "Corner, newCC : " << i - 1 << " " << j - 1 << " " << k + ar[i - 1] - C << " " << m - 1 << "\n";}
						//if (k - ar[i - 1] >= 0 && m && (j >= m || i == n) && j < i) {cout << "Corner, con2oldCC : " << i - 1 << " " << j << " " << k - ar[i - 1] - C << " " << m - 1 << "\n";}
					}
					*/
				}
				
			}
		}
	}
	int res = 0;
	for (int i = 0; i <= l; i++)
	{
		res = (res + dp[n & 1][1][C + i][2]) % MD;
	}
	cout << res << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 6 ms 1024 KB Output is correct
5 Correct 12 ms 1408 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 11 ms 1280 KB Output is correct
8 Correct 11 ms 1280 KB Output is correct
9 Correct 11 ms 1408 KB Output is correct
10 Correct 11 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1824 KB Output is correct
2 Correct 33 ms 2040 KB Output is correct
3 Correct 33 ms 2048 KB Output is correct
4 Correct 34 ms 2048 KB Output is correct
5 Correct 33 ms 2040 KB Output is correct
6 Correct 35 ms 2040 KB Output is correct
7 Correct 34 ms 2040 KB Output is correct
8 Correct 33 ms 2040 KB Output is correct
9 Correct 35 ms 2040 KB Output is correct
10 Correct 33 ms 2040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 6 ms 1024 KB Output is correct
5 Correct 12 ms 1408 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 11 ms 1280 KB Output is correct
8 Correct 11 ms 1280 KB Output is correct
9 Correct 11 ms 1408 KB Output is correct
10 Correct 11 ms 1280 KB Output is correct
11 Correct 24 ms 1824 KB Output is correct
12 Correct 33 ms 2040 KB Output is correct
13 Correct 33 ms 2048 KB Output is correct
14 Correct 34 ms 2048 KB Output is correct
15 Correct 33 ms 2040 KB Output is correct
16 Correct 35 ms 2040 KB Output is correct
17 Correct 34 ms 2040 KB Output is correct
18 Correct 33 ms 2040 KB Output is correct
19 Correct 35 ms 2040 KB Output is correct
20 Correct 33 ms 2040 KB Output is correct
21 Correct 287 ms 5284 KB Output is correct
22 Correct 1256 ms 11384 KB Output is correct
23 Correct 1857 ms 14664 KB Output is correct
24 Incorrect 1937 ms 14376 KB Output isn't correct
25 Halted 0 ms 0 KB -