답안 #102608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102608 2019-03-26T08:34:54 Z Minnakhmetov Skyscraper (JOI16_skyscraper) C++14
100 / 100
57 ms 15992 KB
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
#pragma warning(disable : 4996)

const int N = 101, L = 1001, MOD = 1e9 + 7;
int dp[N][N][L][3], a[N];

void f(int &a, ll b) {
	a = (a + b) % MOD;
}

signed main() {
#ifdef HOME
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, l;
	cin >> n >> l;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a, a + n);

	dp[1][0][0][0] = 1;
	dp[1][0][0][2] = 1;
	dp[1][0][0][1] = 2;

	for (int i = 1; i < n; i++) {
		int d = a[i] - a[i - 1];
		for (int j = 0; j < i; j++) {
			for (int k = 0; k <= l; k++) {
				for (int x = 0; x < 3; x++) {
					int nk = k + (x + j * 2) * d;
					if (dp[i][j][k][x] && nk <= l) {
						ll cur = dp[i][j][k][x];
						if (j) {
							f(dp[i + 1][j - 1][nk][x], cur * j);
							f(dp[i + 1][j + 1][nk][x], cur * j);
							f(dp[i + 1][j][nk][x], (cur + cur) * j);

						}
						if (x) {
							f(dp[i + 1][j][nk][x - 1], cur * x);
							f(dp[i + 1][j][nk][x], cur * x);

							f(dp[i + 1][j + 1][nk][x - 1], cur * x);
							f(dp[i + 1][j + 1][nk][x], cur * x);
						}
					}
				}
			}
		}
	}

	ll ans = 0;

	for (int i = 0; i <= l; i++)
		ans += dp[n][0][i][0];

	ans %= MOD;

	cout << ans;
	
	return 0;
}

Compilation message

skyscraper.cpp:41:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 3 ms 768 KB Output is correct
20 Correct 2 ms 768 KB Output is correct
21 Correct 4 ms 1280 KB Output is correct
22 Correct 57 ms 15992 KB Output is correct
23 Correct 50 ms 6352 KB Output is correct
24 Correct 40 ms 9080 KB Output is correct
25 Correct 41 ms 7032 KB Output is correct
26 Correct 36 ms 6776 KB Output is correct
27 Correct 25 ms 8312 KB Output is correct
28 Correct 29 ms 9724 KB Output is correct
29 Correct 41 ms 12280 KB Output is correct
30 Correct 57 ms 7188 KB Output is correct