#include <bits/stdc++.h>
#define nl "\n"
#define no "NO"
#define yes "YES"
#define fi first
#define se second
#define vec vector
#define task "main"
#define _mp make_pair
#define ii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define evoid(val) return void(std::cout << val)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin())
using namespace std;
template<typename U, typename V> bool maxi(U &a, V b) {
if (a < b) { a = b; return 1; } return 0;
}
template<typename U, typename V> bool mini(U &a, V b) {
if (a > b or a == -1) { a = b; return 1; } return 0;
}
const int N = (int)2e5 + 9;
const int mod = (int)1e9 + 7;
void prepare(); void main_code();
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
const bool MULTITEST = 0; prepare();
int num_test = 1; if (MULTITEST) cin >> num_test;
while (num_test--) { main_code(); }
}
void prepare() {};
int n, l, r;
int a[N];
long long s[N];
namespace SUB1 {
void sol() {
int ans = INT_MAX;
for(int mask = 0; mask < (1 << n); ++mask) {
if (!(1 & mask >> (n - 1))) continue ;
int X = __builtin_popcount(mask);
if (X < l or X > r) continue ;
int OR = 0;
int sum = 0;
for(int i = 0; i < n; ++i) {
sum += a[i + 1];
if (1 & mask >> i) {
OR |= sum;
sum = 0;
}
}
ans = min(ans, OR);
}
cout << ans;
}
};
namespace SUB2 {
const int N = 51;
const int MAX = (1 << 9);
bool dp[N][N][MAX];
void sol() {
dp[0][0][0] = 1;
for(int i = 0; i < n; ++i)
for(int j = 0; j < r; ++j)
for(int z = 0; z < MAX; ++z) if (dp[i][j][z]) {
for(int k = i + 1; k <= n; ++k) {
dp[k][j + 1][z | (s[k] - s[i])] = 1;
}
}
int res = MAX;
FOR(i, l, r)
FOR(v, 0, MAX - 1)
if (dp[n][i][v])
res = min(res, v);
cout << res;
}
};
namespace SUB3 {
const int N = 102;
const int MAX = (1 << 11);
int dp[N][MAX];
void sol() {
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
for(int i = 0; i < n; ++i)
for(int z = 0; z < MAX; ++z) if (dp[i][z] != -1) {
for(int k = i + 1; k <= n; ++k) {
mini(dp[k][z | (s[k] - s[i])], dp[i][z] + 1);
}
}
int res = MAX;
FOR(i, l, r)
FOR(v, 0, MAX - 1)
if (dp[n][v] != -1 and dp[n][v] <= r)
res = min(res, v);
cout << res;
}
};
void main_code() {
cin >> n >> l >> r;
for(int i = 1; i <= n; ++i) cin >> a[i], s[i] = s[i - 1] + a[i];
if (n <= 20) return SUB1::sol(), void();
if (n <= 50 and *max_element(a + 1, a + n + 1) <= 10) {
SUB2::sol();
return ;
}
if (n <= 100 and l == 1 and *max_element(a + 1, a + n + 1) <= 20) {
SUB3::sol();
return ;
}
}
/* Let the river flows naturally */
Compilation message
sculpture.cpp: In function 'int main()':
sculpture.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2512 KB |
Output is correct |
13 |
Correct |
30 ms |
2520 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
4 ms |
2524 KB |
Output is correct |
22 |
Correct |
4 ms |
2396 KB |
Output is correct |
23 |
Correct |
4 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2396 KB |
Output is correct |
26 |
Correct |
26 ms |
2396 KB |
Output is correct |
27 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2516 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2512 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2516 KB |
Output is correct |
13 |
Correct |
29 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2408 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2508 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
4 ms |
2396 KB |
Output is correct |
22 |
Correct |
4 ms |
2392 KB |
Output is correct |
23 |
Correct |
4 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2396 KB |
Output is correct |
26 |
Correct |
26 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2908 KB |
Output is correct |
31 |
Correct |
2 ms |
2908 KB |
Output is correct |
32 |
Correct |
1 ms |
2908 KB |
Output is correct |
33 |
Correct |
0 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2908 KB |
Output is correct |
35 |
Correct |
1 ms |
2908 KB |
Output is correct |
36 |
Correct |
1 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2520 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
30 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2908 KB |
Output is correct |
18 |
Correct |
2 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2904 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
3028 KB |
Output is correct |
22 |
Correct |
1 ms |
2908 KB |
Output is correct |
23 |
Correct |
1 ms |
2908 KB |
Output is correct |
24 |
Correct |
1 ms |
3164 KB |
Output is correct |
25 |
Correct |
1 ms |
3164 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
3332 KB |
Output is correct |
29 |
Correct |
2 ms |
3164 KB |
Output is correct |
30 |
Correct |
1 ms |
3164 KB |
Output is correct |
31 |
Correct |
2 ms |
3340 KB |
Output is correct |
32 |
Correct |
2 ms |
3416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2424 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2512 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
32 ms |
2392 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2512 KB |
Output is correct |
21 |
Correct |
4 ms |
2392 KB |
Output is correct |
22 |
Correct |
4 ms |
2392 KB |
Output is correct |
23 |
Correct |
4 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2532 KB |
Output is correct |
25 |
Correct |
4 ms |
2396 KB |
Output is correct |
26 |
Correct |
26 ms |
2396 KB |
Output is correct |
27 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
36 ms |
2504 KB |
Output is correct |
14 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |