답안 #41402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41402 2018-02-17T06:58:32 Z fest Bali Sculptures (APIO15_sculpture) C++14
100 / 100
462 ms 211544 KB
// fest
#include <bits/stdc++.h>	

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define FILENAME ""
#define __ fflush(stdout)

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef COMP
		freopen(".in", "r", stdin);
		freopen("2.out", "w", stdout);
	#else
		freopen(FILENAME".in", "r", stdin);
		freopen(FILENAME".out", "w", stdout);
	#endif
}                           

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 2001, inf = 1e9 * 2, MOD = (int)1e9 + 7, M = 42;

char CH[N];

const ll INF = 1e18;

const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};

ll a[N];               

int d[N];

map<ll, bool> dp[N][N];

void solve1(int n, int r) {
  for (int i = 1; i <= n; i++) scanf("%lld ", a + i);
	ll ans = 0;
	ll no = 0;
	for (int bit = M - 1; bit >= 0; bit--) {
		ll now = (ans | (1ll << bit));
		now--;
		no |= (1ll << bit);
		for (int i = 1; i <= n; i++) d[i] = inf;
		for (int i = 1; i <= n; i++) {
			ll sum = a[i];
			for (int j = i - 1; j >= 0; j--) {
				if (sum & no) {
					sum += a[j];
					continue;
				}
				if (sum > now) break;
				d[i] = min(d[i], d[j] + 1);	
				sum += a[j];
			}
		}
		no ^= (1ll << bit);
		if (d[n] <= r) no |= (1ll << bit);
		else ans |= (1ll << bit);
	}
	cout << ans;
}

void solve2(int n, int l, int r) {
	for (int i = 1; i <= n; i++) scanf("%lld ", a + i);
	ll should = INF;
	for (int i = 50; i >= 0; i--) {
		int bl = 0;
		for (int j = 1; j <= n;) {
			ll now = a[j];
			int rig = j + 1;
			while (rig <= n && now + a[rig] < (1ll << i)) now += a[rig], rig++;
			if (now >= (1ll << i)) {
				bl = r + 1;
				break;
			}
			bl++;
			j = rig;	
		}
		if (bl <= r) should = (1ll << i);
		else break;
	}
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int k = 1; k <= r; k++) {
			ll sum = a[i];
			for (int j = i - 1; j >= 0; j--) {
				if (sum >= should) break;
				for (auto m : dp[j][k - 1]) if ((m.F | sum) < should) dp[i][k][(m.F | sum)] = 1;
				sum += a[j];	
			}
		}
	}
	ll ans = INF;
	for (int k = l; k <= r; k++) for (auto m : dp[n][k]) ans = min(ans, m.F);
	cout << ans;	
}

int main() {
  
	int n, l, r;
	cin >> n >> l >> r;
	if (l == 1) solve1(n, r);
	else solve2(n, l, r);
	return 0;	
}

Compilation message

sculpture.cpp: In function 'void FREOPEN()':
sculpture.cpp:25:37: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(FILENAME".in", "r", stdin);
                                     ^
sculpture.cpp:26:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(FILENAME".out", "w", stdout);
                                       ^
sculpture.cpp: In function 'void solve1(int, int)':
sculpture.cpp:48:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 1; i <= n; i++) scanf("%lld ", a + i);
                                                     ^
sculpture.cpp: In function 'void solve2(int, int, int)':
sculpture.cpp:76:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%lld ", a + i);
                                                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 188280 KB Output is correct
2 Correct 155 ms 188440 KB Output is correct
3 Correct 154 ms 188584 KB Output is correct
4 Correct 156 ms 188620 KB Output is correct
5 Correct 158 ms 188620 KB Output is correct
6 Correct 152 ms 188620 KB Output is correct
7 Correct 157 ms 188620 KB Output is correct
8 Correct 158 ms 188620 KB Output is correct
9 Correct 154 ms 188620 KB Output is correct
10 Correct 164 ms 188620 KB Output is correct
11 Correct 155 ms 188620 KB Output is correct
12 Correct 157 ms 188620 KB Output is correct
13 Correct 157 ms 188620 KB Output is correct
14 Correct 154 ms 188620 KB Output is correct
15 Correct 156 ms 188620 KB Output is correct
16 Correct 155 ms 188620 KB Output is correct
17 Correct 155 ms 188624 KB Output is correct
18 Correct 152 ms 188624 KB Output is correct
19 Correct 162 ms 188624 KB Output is correct
20 Correct 164 ms 188624 KB Output is correct
21 Correct 168 ms 188632 KB Output is correct
22 Correct 151 ms 188640 KB Output is correct
23 Correct 164 ms 188640 KB Output is correct
24 Correct 167 ms 188640 KB Output is correct
25 Correct 159 ms 188764 KB Output is correct
26 Correct 158 ms 188764 KB Output is correct
27 Correct 154 ms 188764 KB Output is correct
28 Correct 161 ms 188764 KB Output is correct
29 Correct 158 ms 188764 KB Output is correct
30 Correct 158 ms 188764 KB Output is correct
31 Correct 158 ms 188764 KB Output is correct
32 Correct 160 ms 188764 KB Output is correct
33 Correct 156 ms 188764 KB Output is correct
34 Correct 152 ms 188764 KB Output is correct
35 Correct 153 ms 188764 KB Output is correct
36 Correct 156 ms 188764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 188764 KB Output is correct
2 Correct 165 ms 188764 KB Output is correct
3 Correct 152 ms 188764 KB Output is correct
4 Correct 152 ms 188764 KB Output is correct
5 Correct 157 ms 188764 KB Output is correct
6 Correct 157 ms 188764 KB Output is correct
7 Correct 158 ms 188764 KB Output is correct
8 Correct 161 ms 188764 KB Output is correct
9 Correct 177 ms 188764 KB Output is correct
10 Correct 154 ms 188764 KB Output is correct
11 Correct 173 ms 188764 KB Output is correct
12 Correct 161 ms 188764 KB Output is correct
13 Correct 153 ms 188764 KB Output is correct
14 Correct 158 ms 188764 KB Output is correct
15 Correct 159 ms 188764 KB Output is correct
16 Correct 162 ms 188764 KB Output is correct
17 Correct 155 ms 188764 KB Output is correct
18 Correct 157 ms 188764 KB Output is correct
19 Correct 173 ms 188764 KB Output is correct
20 Correct 161 ms 188776 KB Output is correct
21 Correct 161 ms 188776 KB Output is correct
22 Correct 165 ms 188776 KB Output is correct
23 Correct 161 ms 188776 KB Output is correct
24 Correct 161 ms 188776 KB Output is correct
25 Correct 160 ms 188776 KB Output is correct
26 Correct 163 ms 188776 KB Output is correct
27 Correct 165 ms 188780 KB Output is correct
28 Correct 153 ms 188780 KB Output is correct
29 Correct 160 ms 188780 KB Output is correct
30 Correct 161 ms 188780 KB Output is correct
31 Correct 160 ms 188780 KB Output is correct
32 Correct 154 ms 188784 KB Output is correct
33 Correct 154 ms 188784 KB Output is correct
34 Correct 168 ms 188784 KB Output is correct
35 Correct 158 ms 188784 KB Output is correct
36 Correct 162 ms 188784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 160 ms 188784 KB Output is correct
2 Correct 151 ms 188784 KB Output is correct
3 Correct 156 ms 188784 KB Output is correct
4 Correct 158 ms 188784 KB Output is correct
5 Correct 159 ms 188784 KB Output is correct
6 Correct 151 ms 188784 KB Output is correct
7 Correct 159 ms 188784 KB Output is correct
8 Correct 155 ms 188784 KB Output is correct
9 Correct 163 ms 188784 KB Output is correct
10 Correct 158 ms 188784 KB Output is correct
11 Correct 157 ms 188784 KB Output is correct
12 Correct 158 ms 188784 KB Output is correct
13 Correct 162 ms 188784 KB Output is correct
14 Correct 161 ms 188784 KB Output is correct
15 Correct 160 ms 188784 KB Output is correct
16 Correct 153 ms 188784 KB Output is correct
17 Correct 153 ms 188784 KB Output is correct
18 Correct 154 ms 188784 KB Output is correct
19 Correct 160 ms 188784 KB Output is correct
20 Correct 156 ms 188784 KB Output is correct
21 Correct 155 ms 188784 KB Output is correct
22 Correct 161 ms 188784 KB Output is correct
23 Correct 159 ms 188844 KB Output is correct
24 Correct 167 ms 188844 KB Output is correct
25 Correct 152 ms 188844 KB Output is correct
26 Correct 153 ms 188844 KB Output is correct
27 Correct 173 ms 188844 KB Output is correct
28 Correct 157 ms 188844 KB Output is correct
29 Correct 167 ms 188844 KB Output is correct
30 Correct 157 ms 188844 KB Output is correct
31 Correct 155 ms 188844 KB Output is correct
32 Correct 155 ms 188844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 188844 KB Output is correct
2 Correct 158 ms 188844 KB Output is correct
3 Correct 163 ms 188844 KB Output is correct
4 Correct 159 ms 188844 KB Output is correct
5 Correct 158 ms 188844 KB Output is correct
6 Correct 161 ms 188844 KB Output is correct
7 Correct 155 ms 188844 KB Output is correct
8 Correct 155 ms 188844 KB Output is correct
9 Correct 154 ms 188844 KB Output is correct
10 Correct 162 ms 188844 KB Output is correct
11 Correct 161 ms 188844 KB Output is correct
12 Correct 161 ms 188844 KB Output is correct
13 Correct 158 ms 188844 KB Output is correct
14 Correct 161 ms 188844 KB Output is correct
15 Correct 162 ms 188844 KB Output is correct
16 Correct 155 ms 188844 KB Output is correct
17 Correct 157 ms 188844 KB Output is correct
18 Correct 165 ms 188844 KB Output is correct
19 Correct 161 ms 188844 KB Output is correct
20 Correct 171 ms 188844 KB Output is correct
21 Correct 154 ms 188844 KB Output is correct
22 Correct 154 ms 188844 KB Output is correct
23 Correct 154 ms 188844 KB Output is correct
24 Correct 162 ms 188844 KB Output is correct
25 Correct 161 ms 188844 KB Output is correct
26 Correct 153 ms 188844 KB Output is correct
27 Correct 154 ms 188844 KB Output is correct
28 Correct 156 ms 188844 KB Output is correct
29 Correct 164 ms 188844 KB Output is correct
30 Correct 157 ms 188844 KB Output is correct
31 Correct 153 ms 188844 KB Output is correct
32 Correct 161 ms 188844 KB Output is correct
33 Correct 157 ms 188844 KB Output is correct
34 Correct 155 ms 188844 KB Output is correct
35 Correct 161 ms 188844 KB Output is correct
36 Correct 160 ms 188844 KB Output is correct
37 Correct 160 ms 188844 KB Output is correct
38 Correct 173 ms 188844 KB Output is correct
39 Correct 156 ms 188844 KB Output is correct
40 Correct 155 ms 188844 KB Output is correct
41 Correct 165 ms 188844 KB Output is correct
42 Correct 158 ms 188844 KB Output is correct
43 Correct 161 ms 188844 KB Output is correct
44 Correct 162 ms 188844 KB Output is correct
45 Correct 161 ms 188844 KB Output is correct
46 Correct 164 ms 188844 KB Output is correct
47 Correct 154 ms 188844 KB Output is correct
48 Correct 155 ms 188844 KB Output is correct
49 Correct 159 ms 188844 KB Output is correct
50 Correct 153 ms 188844 KB Output is correct
51 Correct 162 ms 188844 KB Output is correct
52 Correct 163 ms 188844 KB Output is correct
53 Correct 157 ms 188844 KB Output is correct
54 Correct 157 ms 188844 KB Output is correct
55 Correct 161 ms 188844 KB Output is correct
56 Correct 165 ms 188872 KB Output is correct
57 Correct 162 ms 188872 KB Output is correct
58 Correct 162 ms 188872 KB Output is correct
59 Correct 160 ms 188872 KB Output is correct
60 Correct 152 ms 188872 KB Output is correct
61 Correct 161 ms 188872 KB Output is correct
62 Correct 163 ms 188872 KB Output is correct
63 Correct 163 ms 188872 KB Output is correct
64 Correct 166 ms 189048 KB Output is correct
65 Correct 169 ms 189048 KB Output is correct
66 Correct 268 ms 197744 KB Output is correct
67 Correct 221 ms 197744 KB Output is correct
68 Correct 163 ms 197744 KB Output is correct
69 Correct 160 ms 197744 KB Output is correct
70 Correct 160 ms 197744 KB Output is correct
71 Correct 165 ms 197744 KB Output is correct
72 Correct 178 ms 197744 KB Output is correct
73 Correct 193 ms 197744 KB Output is correct
74 Correct 462 ms 211544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 211544 KB Output is correct
2 Correct 153 ms 211544 KB Output is correct
3 Correct 154 ms 211544 KB Output is correct
4 Correct 156 ms 211544 KB Output is correct
5 Correct 152 ms 211544 KB Output is correct
6 Correct 159 ms 211544 KB Output is correct
7 Correct 150 ms 211544 KB Output is correct
8 Correct 152 ms 211544 KB Output is correct
9 Correct 155 ms 211544 KB Output is correct
10 Correct 159 ms 211544 KB Output is correct
11 Correct 156 ms 211544 KB Output is correct
12 Correct 159 ms 211544 KB Output is correct
13 Correct 155 ms 211544 KB Output is correct
14 Correct 157 ms 211544 KB Output is correct
15 Correct 158 ms 211544 KB Output is correct
16 Correct 155 ms 211544 KB Output is correct
17 Correct 157 ms 211544 KB Output is correct
18 Correct 157 ms 211544 KB Output is correct
19 Correct 159 ms 211544 KB Output is correct
20 Correct 156 ms 211544 KB Output is correct
21 Correct 162 ms 211544 KB Output is correct
22 Correct 152 ms 211544 KB Output is correct
23 Correct 159 ms 211544 KB Output is correct
24 Correct 155 ms 211544 KB Output is correct
25 Correct 154 ms 211544 KB Output is correct
26 Correct 154 ms 211544 KB Output is correct
27 Correct 152 ms 211544 KB Output is correct
28 Correct 154 ms 211544 KB Output is correct
29 Correct 152 ms 211544 KB Output is correct
30 Correct 152 ms 211544 KB Output is correct
31 Correct 154 ms 211544 KB Output is correct
32 Correct 153 ms 211544 KB Output is correct
33 Correct 156 ms 211544 KB Output is correct
34 Correct 165 ms 211544 KB Output is correct
35 Correct 153 ms 211544 KB Output is correct
36 Correct 160 ms 211544 KB Output is correct
37 Correct 153 ms 211544 KB Output is correct
38 Correct 154 ms 211544 KB Output is correct
39 Correct 153 ms 211544 KB Output is correct
40 Correct 152 ms 211544 KB Output is correct
41 Correct 153 ms 211544 KB Output is correct
42 Correct 153 ms 211544 KB Output is correct
43 Correct 158 ms 211544 KB Output is correct
44 Correct 158 ms 211544 KB Output is correct
45 Correct 156 ms 211544 KB Output is correct
46 Correct 156 ms 211544 KB Output is correct
47 Correct 165 ms 211544 KB Output is correct
48 Correct 155 ms 211544 KB Output is correct
49 Correct 152 ms 211544 KB Output is correct
50 Correct 157 ms 211544 KB Output is correct
51 Correct 159 ms 211544 KB Output is correct
52 Correct 164 ms 211544 KB Output is correct
53 Correct 165 ms 211544 KB Output is correct
54 Correct 178 ms 211544 KB Output is correct
55 Correct 177 ms 211544 KB Output is correct
56 Correct 237 ms 211544 KB Output is correct
57 Correct 234 ms 211544 KB Output is correct
58 Correct 227 ms 211544 KB Output is correct
59 Correct 237 ms 211544 KB Output is correct
60 Correct 236 ms 211544 KB Output is correct
61 Correct 152 ms 211544 KB Output is correct
62 Correct 164 ms 211544 KB Output is correct
63 Correct 178 ms 211544 KB Output is correct
64 Correct 195 ms 211544 KB Output is correct
65 Correct 212 ms 211544 KB Output is correct
66 Correct 217 ms 211544 KB Output is correct
67 Correct 239 ms 211544 KB Output is correct
68 Correct 237 ms 211544 KB Output is correct
69 Correct 232 ms 211544 KB Output is correct