Submission #102527

# Submission time Handle Problem Language Result Execution time Memory
102527 2019-03-25T17:26:59 Z Minnakhmetov Skyscraper (JOI16_skyscraper) C++14
20 / 100
35 ms 4280 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 = 15, S = 3e4 + 5, MOD = 1e9 + 7;
int a[N], dp[N][2][2][N][S];

void f(int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= 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);
	reverse(a, a + n);

	dp[1][0][0][0][0] = 1;
	dp[1][1][1][0][a[0] + a[0]] = 1;
	dp[1][0][1][0][a[0]] = 1;
	dp[1][1][0][0][a[0]] = 1;
	
	for (int i = 1; i < n; i++) {
		for (int x = 0; x < 2; x++) {
			for (int y = 0; y < 2; y++) {
				for (int j = 0; j < i; j++) {
					for (int k = 0; k < S; k++) {
						if (dp[i][x][y][j][k]) {
							int cur = dp[i][x][y][j][k];
							if (j) {
								f(dp[i + 1][x][y][j][k], cur * j * 2 % MOD);
								f(dp[i + 1][x][y][j + 1][k + a[i] + a[i]], cur * j % MOD);
								f(dp[i + 1][x][y][j - 1][k - a[i] - a[i]], cur * j % MOD);
							}
							if (x) {
								f(dp[i + 1][0][y][j][k - a[i]], cur);
								f(dp[i + 1][1][y][j][k], cur);
								f(dp[i + 1][0][y][j + 1][k + a[i]], cur);
								f(dp[i + 1][1][y][j + 1][k + a[i] + a[i]], cur);
							}
							if (y) {
								f(dp[i + 1][x][0][j][k - a[i]], cur);
								f(dp[i + 1][x][1][j][k], cur);
								f(dp[i + 1][x][0][j + 1][k + a[i]], cur);
								f(dp[i + 1][x][1][j + 1][k + a[i] + a[i]], cur);
							}
						}
					}
				}
			}
		}
	}

	//for (int x = 0; x < 2; x++) {
	//	for (int y = 0; y < 2; y++) {
	//		for (int j = 0; j < 4; j++) {
	//			for (int k = 0; k < 15; k++) {
	//				cout << x << " " << y << " " << j << " " << k << " : " << dp[4][x][y][j][k] << "\n";
	//			}
	//		}
	//	}
	//}
	

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

	cout << ans;
	
	return 0;
}

Compilation message

skyscraper.cpp:41:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 10 ms 1920 KB Output is correct
6 Correct 10 ms 2048 KB Output is correct
7 Correct 10 ms 1280 KB Output is correct
8 Correct 8 ms 1152 KB Output is correct
9 Correct 9 ms 1920 KB Output is correct
10 Correct 11 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1784 KB Output is correct
2 Correct 23 ms 2816 KB Output is correct
3 Correct 24 ms 2304 KB Output is correct
4 Correct 22 ms 2688 KB Output is correct
5 Correct 22 ms 2944 KB Output is correct
6 Correct 23 ms 2552 KB Output is correct
7 Correct 24 ms 2304 KB Output is correct
8 Correct 21 ms 2304 KB Output is correct
9 Correct 22 ms 2304 KB Output is correct
10 Correct 25 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 10 ms 1920 KB Output is correct
6 Correct 10 ms 2048 KB Output is correct
7 Correct 10 ms 1280 KB Output is correct
8 Correct 8 ms 1152 KB Output is correct
9 Correct 9 ms 1920 KB Output is correct
10 Correct 11 ms 1152 KB Output is correct
11 Correct 18 ms 1784 KB Output is correct
12 Correct 23 ms 2816 KB Output is correct
13 Correct 24 ms 2304 KB Output is correct
14 Correct 22 ms 2688 KB Output is correct
15 Correct 22 ms 2944 KB Output is correct
16 Correct 23 ms 2552 KB Output is correct
17 Correct 24 ms 2304 KB Output is correct
18 Correct 21 ms 2304 KB Output is correct
19 Correct 22 ms 2304 KB Output is correct
20 Correct 25 ms 2680 KB Output is correct
21 Runtime error 35 ms 4280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Halted 0 ms 0 KB -