답안 #108254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108254 2019-04-28T11:10:58 Z kek Bali Sculptures (APIO15_sculpture) C++17
71 / 100
1000 ms 4796 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair

#define debug(x) cout << #x << " = " << x << endl;

const int INF = 1e18 + 666;

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

#ifndef LOCAL
void UseFiles(const string &s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
	// UseFiles("cowboys");
	iostream::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	run();
}

int can_get(int cur, int bit, const vector<int> &v, int a, int b) {
	int n = len(v);
	vector<int> pref(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		pref[i + 1] = pref[i] + v[i];
	}
	vector<vector<int>> dp(b + 1, vector<int>(n + 1, 0));
	dp[0][0] = 1;
	for (int i = 1; i <= b; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 0; k < j; ++k) {
				int sm = pref[j] - pref[k];
				if (((sm | cur) >> bit) == (cur >> bit)) {
					dp[i][j] |= dp[i - 1][k];
				}
			}
		}
	}
	int ans = 0;
	for (int i = a; i <= b; ++i) {
		ans |= dp[i].back();
	}
	return ans;
}

int get_min_blocks(const vector<int> &v, int cur, int bit) {
	int n = len(v);
	vector<int> pref(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		pref[i + 1] = pref[i] + v[i];
	}
	vector<int> dp(n + 1, INF);
	dp[0] = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < i; ++j) {
			int sm = pref[i] - pref[j];
			if (((sm | cur) >> bit) == (sm >> bit)) {
				cmin(dp[i], dp[j] + 1);
			}
		}
	}
	return dp.back();
}

void run() {
	int n, a, b;
	cin >> n >> a >> b;
	vector<int> v(n);
	for (auto &x : v) {
		cin >> x;
	}
	int cur = 0;
	if (a != 0) {
		for (int i = 43; i > -1; --i) {
			// cur |= (1 << i);
			if (!can_get(cur, i, v, a, b)) {
				cur |= (1ll << i);
				// assert(can_get(cur, i, v, a, b));
			}
		}
	} else {
		for (int i = 43; i > -1; --i) {
			if (get_min_blocks(v, cur, i) > b) {
				cur |= (1ll << i);
			}
		}
	}
	cout << cur << endl;
}

Compilation message

sculpture.cpp: In function 'void UseFiles(const string&)':
sculpture.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen((s + ".in").c_str(), "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen((s + ".out").c_str(), "w", stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 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 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 256 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 3 ms 356 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 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 9 ms 384 KB Output is correct
27 Correct 24 ms 384 KB Output is correct
28 Correct 45 ms 384 KB Output is correct
29 Correct 49 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 22 ms 384 KB Output is correct
32 Correct 34 ms 384 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 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 428 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 6 ms 384 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 9 ms 512 KB Output is correct
50 Correct 23 ms 384 KB Output is correct
51 Correct 58 ms 384 KB Output is correct
52 Correct 51 ms 476 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 23 ms 384 KB Output is correct
55 Correct 39 ms 384 KB Output is correct
56 Correct 4 ms 384 KB Output is correct
57 Correct 8 ms 384 KB Output is correct
58 Correct 19 ms 384 KB Output is correct
59 Correct 40 ms 456 KB Output is correct
60 Correct 39 ms 384 KB Output is correct
61 Correct 3 ms 384 KB Output is correct
62 Correct 40 ms 384 KB Output is correct
63 Correct 41 ms 504 KB Output is correct
64 Correct 36 ms 504 KB Output is correct
65 Correct 4 ms 384 KB Output is correct
66 Correct 5 ms 384 KB Output is correct
67 Correct 8 ms 384 KB Output is correct
68 Correct 18 ms 384 KB Output is correct
69 Correct 38 ms 384 KB Output is correct
70 Correct 42 ms 456 KB Output is correct
71 Correct 3 ms 384 KB Output is correct
72 Correct 37 ms 384 KB Output is correct
73 Correct 31 ms 384 KB Output is correct
74 Correct 25 ms 384 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 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 10 ms 384 KB Output is correct
37 Correct 27 ms 460 KB Output is correct
38 Correct 51 ms 384 KB Output is correct
39 Correct 50 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 26 ms 384 KB Output is correct
42 Correct 39 ms 472 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 8 ms 384 KB Output is correct
45 Correct 18 ms 384 KB Output is correct
46 Correct 38 ms 384 KB Output is correct
47 Correct 37 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 39 ms 508 KB Output is correct
50 Correct 53 ms 384 KB Output is correct
51 Correct 7 ms 484 KB Output is correct
52 Correct 975 ms 964 KB Output is correct
53 Execution timed out 1064 ms 4796 KB Time limit exceeded
54 Halted 0 ms 0 KB -