/*
Solution for APIO 2015 - Bali Sculpture
Tags :
*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
ll MOD = 1000000007;
ll power(ll base, ll n){
if (n == 0) return 1;
if (n == 1) return base;
ll halfn = power(base, n/2);
if (n % 2 == 0) return (halfn * halfn) % MOD;
return (((halfn * halfn) % MOD) * base) % MOD;
}
ll inverse(ll n){
return power(n, MOD-2);
}
ll add(ll a, ll b){
return (a+b) % MOD;
}
ll mul(ll a, ll b){
a %= MOD;
return (a*b) % MOD;
}
ll gcd(ll a, ll b){
if (a == 1) return 1;
if (a == 0) return b;
return gcd(b%a, a);
}
void solve(){
int n, a, b; cin >> n >> a >> b;
vector<ll> y(n+1); FOR(i,1,n+1) cin >> y[i];
vector<ll> p(n+1); FOR(i,1,n+1) p[i] = p[i-1] + y[i];
ll ans = MOD*MOD;
FOR(mask,0,(1<<(n-1))){
ll val = 0; int cnt = 0; int cur = 0;
FOR(i,0,n-1){
if (mask&(1<<i)){
cnt++;
val |= (p[i+1]-p[cur]);
cur = i+1;
}
}
cnt++; val |= (p[n]-p[cur]);
if (a <= cnt && cnt <= b) ans = min(ans, val);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
int TC = 1;
//cin >> TC;
FOR(i, 1, TC+1){
//cout << "Case #" << i << ": ";
solve();
}
}
Compilation message
sculpture.cpp:10: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
10 | #pragma GCC optimization ("Ofast")
|
sculpture.cpp:11: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
11 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
30 ms |
300 KB |
Output is correct |
9 |
Correct |
28 ms |
212 KB |
Output is correct |
10 |
Correct |
29 ms |
212 KB |
Output is correct |
11 |
Correct |
29 ms |
212 KB |
Output is correct |
12 |
Correct |
29 ms |
304 KB |
Output is correct |
13 |
Correct |
30 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
4 ms |
320 KB |
Output is correct |
21 |
Correct |
31 ms |
212 KB |
Output is correct |
22 |
Correct |
29 ms |
212 KB |
Output is correct |
23 |
Correct |
29 ms |
212 KB |
Output is correct |
24 |
Correct |
29 ms |
212 KB |
Output is correct |
25 |
Correct |
28 ms |
212 KB |
Output is correct |
26 |
Correct |
30 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
16 ms |
320 KB |
Output is correct |
31 |
Correct |
29 ms |
308 KB |
Output is correct |
32 |
Correct |
31 ms |
300 KB |
Output is correct |
33 |
Correct |
32 ms |
296 KB |
Output is correct |
34 |
Correct |
32 ms |
212 KB |
Output is correct |
35 |
Correct |
28 ms |
212 KB |
Output is correct |
36 |
Correct |
29 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
29 ms |
212 KB |
Output is correct |
9 |
Correct |
29 ms |
300 KB |
Output is correct |
10 |
Correct |
30 ms |
212 KB |
Output is correct |
11 |
Correct |
29 ms |
300 KB |
Output is correct |
12 |
Correct |
29 ms |
212 KB |
Output is correct |
13 |
Correct |
29 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
316 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
4 ms |
212 KB |
Output is correct |
21 |
Correct |
29 ms |
212 KB |
Output is correct |
22 |
Correct |
29 ms |
212 KB |
Output is correct |
23 |
Correct |
28 ms |
212 KB |
Output is correct |
24 |
Correct |
29 ms |
212 KB |
Output is correct |
25 |
Correct |
28 ms |
212 KB |
Output is correct |
26 |
Correct |
30 ms |
212 KB |
Output is correct |
27 |
Correct |
59 ms |
212 KB |
Output is correct |
28 |
Correct |
975 ms |
296 KB |
Output is correct |
29 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
316 KB |
Output is correct |
8 |
Correct |
30 ms |
212 KB |
Output is correct |
9 |
Correct |
31 ms |
312 KB |
Output is correct |
10 |
Correct |
29 ms |
212 KB |
Output is correct |
11 |
Correct |
30 ms |
300 KB |
Output is correct |
12 |
Correct |
28 ms |
212 KB |
Output is correct |
13 |
Correct |
30 ms |
308 KB |
Output is correct |
14 |
Correct |
59 ms |
296 KB |
Output is correct |
15 |
Correct |
987 ms |
296 KB |
Output is correct |
16 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
29 ms |
212 KB |
Output is correct |
9 |
Correct |
29 ms |
212 KB |
Output is correct |
10 |
Correct |
31 ms |
300 KB |
Output is correct |
11 |
Correct |
29 ms |
212 KB |
Output is correct |
12 |
Correct |
29 ms |
212 KB |
Output is correct |
13 |
Correct |
30 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
4 ms |
212 KB |
Output is correct |
21 |
Correct |
36 ms |
312 KB |
Output is correct |
22 |
Correct |
29 ms |
212 KB |
Output is correct |
23 |
Correct |
30 ms |
324 KB |
Output is correct |
24 |
Correct |
29 ms |
212 KB |
Output is correct |
25 |
Correct |
30 ms |
320 KB |
Output is correct |
26 |
Correct |
29 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
15 ms |
212 KB |
Output is correct |
31 |
Correct |
29 ms |
212 KB |
Output is correct |
32 |
Correct |
30 ms |
212 KB |
Output is correct |
33 |
Correct |
29 ms |
300 KB |
Output is correct |
34 |
Correct |
30 ms |
212 KB |
Output is correct |
35 |
Correct |
29 ms |
280 KB |
Output is correct |
36 |
Correct |
29 ms |
212 KB |
Output is correct |
37 |
Correct |
58 ms |
212 KB |
Output is correct |
38 |
Execution timed out |
1002 ms |
304 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
31 ms |
212 KB |
Output is correct |
9 |
Correct |
31 ms |
212 KB |
Output is correct |
10 |
Correct |
29 ms |
212 KB |
Output is correct |
11 |
Correct |
29 ms |
212 KB |
Output is correct |
12 |
Correct |
30 ms |
212 KB |
Output is correct |
13 |
Correct |
32 ms |
312 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
17 ms |
320 KB |
Output is correct |
18 |
Correct |
29 ms |
212 KB |
Output is correct |
19 |
Correct |
29 ms |
212 KB |
Output is correct |
20 |
Correct |
31 ms |
300 KB |
Output is correct |
21 |
Correct |
31 ms |
316 KB |
Output is correct |
22 |
Correct |
29 ms |
212 KB |
Output is correct |
23 |
Correct |
29 ms |
212 KB |
Output is correct |
24 |
Correct |
63 ms |
296 KB |
Output is correct |
25 |
Correct |
996 ms |
300 KB |
Output is correct |
26 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |