#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
#define int long long
const int MAXN = 2e3+1, LOG = 45;
int n,A,B;
int a[MAXN], p[MAXN], res[LOG];
bool dp[MAXN][MAXN], valid[MAXN][MAXN];
vector<int> v[MAXN][MAXN];
int dp1[MAXN];
void lolwhat() {
dp[0][0] = 1;
FOR(i,0,n) FOR(j,i,n) valid[i][j] = 1;
FORR(k,LOG-1,-1) {
FOR(i,0,n+1) {
FOR(j,1,n+1) dp[i][j] = 0;
}
FOR(j,0,n) {
FOR(i,0,n+1) {
FOR(l,i+1,n+1) {
dp[l][j+1] = dp[l][j+1] || (dp[i][j] && valid[i][l-1] && !v[i][l-1][k]);
}
}
}
res[k] = 1;
FOR(x,A,B+1) {
if (dp[n][x]) res[k] = 0;
}
FOR(i,0,n) {
FOR(j,i,n) {
if (v[i][j][k] && !res[k]) valid[i][j] = 0;
}
}
}
int ans = 0, cur = 1;
FOR(k,0,LOG+1) {
ans += cur*res[k];
cur *= 2;
}
cout << ans;
}
void lolbruh() {
dp1[0] = 0;
FOR(i,0,n) FOR(j,i,n) valid[i][j] = 1;
FORR(k,LOG-1,-1) {
FOR(i,1,n+1) dp1[i] = LLINF;
FOR(i,0,n+1) {
FOR(l,i+1,n+1) {
if (valid[i][l-1] && !v[i][l-1][k]) {
dp1[l] = min(dp1[l], dp1[i]+1);
}
}
}
res[k] = dp1[n] <= B ? 0 : 1;
FOR(i,0,n) {
FOR(j,i,n) {
if (v[i][j][k] && !res[k]) valid[i][j] = 0;
}
}
}
int ans = 0, cur = 1;
FOR(k,0,LOG+1) {
ans += cur*res[k];
cur *= 2;
}
cout << ans;
}
signed main() {
OPTM;
cin >> n >> A >> B;
FOR(i,0,n) cin >> a[i];
FOR(i,1,n+1) p[i] = p[i-1]+a[i-1];
FOR(i,0,n) {
FOR(j,i,n) {
int x = p[j+1]-p[i];
while (x > 0) {
v[i][j].PB(x%2);
x /= 2;
}
int vn = v[i][j].size();
FOR(k,0,LOG-vn) v[i][j].PB(0);
}
}
if (A == 1) lolbruh();
else lolwhat();
}
Compilation message
sculpture.cpp: In function 'void lolwhat()':
sculpture.cpp:59:25: warning: iteration 45 invokes undefined behavior [-Waggressive-loop-optimizations]
59 | ans += cur*res[k];
| ~~~~~^
sculpture.cpp:10:38: note: within this loop
10 | #define FOR(i,s,n) for (int i = s; i < n; i++)
......
58 | FOR(k,0,LOG+1) {
| ~~~~~~~~~
sculpture.cpp:58:5: note: in expansion of macro 'FOR'
58 | FOR(k,0,LOG+1) {
| ^~~
sculpture.cpp: In function 'void lolbruh()':
sculpture.cpp:86:25: warning: iteration 45 invokes undefined behavior [-Waggressive-loop-optimizations]
86 | ans += cur*res[k];
| ~~~~~^
sculpture.cpp:10:38: note: within this loop
10 | #define FOR(i,s,n) for (int i = s; i < n; i++)
......
85 | FOR(k,0,LOG+1) {
| ~~~~~~~~~
sculpture.cpp:85:5: note: in expansion of macro 'FOR'
85 | FOR(k,0,LOG+1) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
94316 KB |
Output is correct |
2 |
Correct |
44 ms |
94292 KB |
Output is correct |
3 |
Correct |
45 ms |
94340 KB |
Output is correct |
4 |
Correct |
45 ms |
94284 KB |
Output is correct |
5 |
Correct |
48 ms |
94392 KB |
Output is correct |
6 |
Correct |
49 ms |
94324 KB |
Output is correct |
7 |
Correct |
45 ms |
94336 KB |
Output is correct |
8 |
Correct |
45 ms |
94376 KB |
Output is correct |
9 |
Correct |
45 ms |
94412 KB |
Output is correct |
10 |
Correct |
46 ms |
94392 KB |
Output is correct |
11 |
Correct |
47 ms |
94400 KB |
Output is correct |
12 |
Correct |
46 ms |
94408 KB |
Output is correct |
13 |
Correct |
45 ms |
94436 KB |
Output is correct |
14 |
Correct |
47 ms |
94284 KB |
Output is correct |
15 |
Correct |
48 ms |
94284 KB |
Output is correct |
16 |
Correct |
46 ms |
94356 KB |
Output is correct |
17 |
Correct |
47 ms |
94328 KB |
Output is correct |
18 |
Correct |
50 ms |
94420 KB |
Output is correct |
19 |
Correct |
48 ms |
94500 KB |
Output is correct |
20 |
Correct |
44 ms |
94412 KB |
Output is correct |
21 |
Correct |
47 ms |
94540 KB |
Output is correct |
22 |
Correct |
56 ms |
94420 KB |
Output is correct |
23 |
Correct |
52 ms |
94500 KB |
Output is correct |
24 |
Correct |
46 ms |
94548 KB |
Output is correct |
25 |
Correct |
45 ms |
94488 KB |
Output is correct |
26 |
Correct |
47 ms |
94412 KB |
Output is correct |
27 |
Correct |
56 ms |
94284 KB |
Output is correct |
28 |
Correct |
54 ms |
94316 KB |
Output is correct |
29 |
Correct |
45 ms |
94428 KB |
Output is correct |
30 |
Correct |
49 ms |
94368 KB |
Output is correct |
31 |
Correct |
45 ms |
94412 KB |
Output is correct |
32 |
Correct |
47 ms |
94376 KB |
Output is correct |
33 |
Correct |
46 ms |
94460 KB |
Output is correct |
34 |
Correct |
57 ms |
94452 KB |
Output is correct |
35 |
Correct |
46 ms |
94412 KB |
Output is correct |
36 |
Correct |
44 ms |
94420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
94360 KB |
Output is correct |
2 |
Correct |
51 ms |
94340 KB |
Output is correct |
3 |
Correct |
43 ms |
94260 KB |
Output is correct |
4 |
Correct |
45 ms |
94352 KB |
Output is correct |
5 |
Correct |
46 ms |
94388 KB |
Output is correct |
6 |
Correct |
45 ms |
94364 KB |
Output is correct |
7 |
Correct |
46 ms |
94412 KB |
Output is correct |
8 |
Correct |
46 ms |
94476 KB |
Output is correct |
9 |
Correct |
48 ms |
94460 KB |
Output is correct |
10 |
Correct |
45 ms |
94440 KB |
Output is correct |
11 |
Correct |
53 ms |
94412 KB |
Output is correct |
12 |
Correct |
48 ms |
94432 KB |
Output is correct |
13 |
Correct |
46 ms |
94416 KB |
Output is correct |
14 |
Correct |
51 ms |
94260 KB |
Output is correct |
15 |
Correct |
47 ms |
94340 KB |
Output is correct |
16 |
Correct |
46 ms |
94364 KB |
Output is correct |
17 |
Correct |
47 ms |
94308 KB |
Output is correct |
18 |
Correct |
46 ms |
94304 KB |
Output is correct |
19 |
Correct |
44 ms |
94412 KB |
Output is correct |
20 |
Correct |
47 ms |
94464 KB |
Output is correct |
21 |
Correct |
45 ms |
94452 KB |
Output is correct |
22 |
Correct |
47 ms |
94436 KB |
Output is correct |
23 |
Correct |
51 ms |
94536 KB |
Output is correct |
24 |
Correct |
51 ms |
94488 KB |
Output is correct |
25 |
Correct |
45 ms |
94412 KB |
Output is correct |
26 |
Correct |
48 ms |
94484 KB |
Output is correct |
27 |
Correct |
48 ms |
94424 KB |
Output is correct |
28 |
Correct |
52 ms |
94540 KB |
Output is correct |
29 |
Correct |
47 ms |
94800 KB |
Output is correct |
30 |
Correct |
49 ms |
94796 KB |
Output is correct |
31 |
Correct |
46 ms |
95032 KB |
Output is correct |
32 |
Correct |
46 ms |
95100 KB |
Output is correct |
33 |
Correct |
46 ms |
95020 KB |
Output is correct |
34 |
Correct |
50 ms |
95072 KB |
Output is correct |
35 |
Correct |
84 ms |
95100 KB |
Output is correct |
36 |
Correct |
47 ms |
95084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
94240 KB |
Output is correct |
2 |
Correct |
55 ms |
94368 KB |
Output is correct |
3 |
Correct |
48 ms |
94300 KB |
Output is correct |
4 |
Correct |
46 ms |
94296 KB |
Output is correct |
5 |
Correct |
48 ms |
94376 KB |
Output is correct |
6 |
Correct |
45 ms |
94436 KB |
Output is correct |
7 |
Correct |
51 ms |
94352 KB |
Output is correct |
8 |
Correct |
50 ms |
94412 KB |
Output is correct |
9 |
Correct |
48 ms |
94520 KB |
Output is correct |
10 |
Correct |
50 ms |
94488 KB |
Output is correct |
11 |
Correct |
47 ms |
94444 KB |
Output is correct |
12 |
Correct |
47 ms |
94424 KB |
Output is correct |
13 |
Correct |
49 ms |
94416 KB |
Output is correct |
14 |
Correct |
51 ms |
94424 KB |
Output is correct |
15 |
Correct |
45 ms |
94464 KB |
Output is correct |
16 |
Correct |
48 ms |
94800 KB |
Output is correct |
17 |
Correct |
46 ms |
94880 KB |
Output is correct |
18 |
Correct |
50 ms |
95052 KB |
Output is correct |
19 |
Correct |
47 ms |
95052 KB |
Output is correct |
20 |
Correct |
49 ms |
95076 KB |
Output is correct |
21 |
Correct |
47 ms |
95100 KB |
Output is correct |
22 |
Correct |
48 ms |
95020 KB |
Output is correct |
23 |
Correct |
49 ms |
95088 KB |
Output is correct |
24 |
Correct |
46 ms |
95124 KB |
Output is correct |
25 |
Correct |
53 ms |
95520 KB |
Output is correct |
26 |
Correct |
51 ms |
96076 KB |
Output is correct |
27 |
Correct |
58 ms |
96620 KB |
Output is correct |
28 |
Correct |
55 ms |
97100 KB |
Output is correct |
29 |
Correct |
53 ms |
97132 KB |
Output is correct |
30 |
Correct |
52 ms |
97036 KB |
Output is correct |
31 |
Correct |
51 ms |
97144 KB |
Output is correct |
32 |
Correct |
49 ms |
97104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
94304 KB |
Output is correct |
2 |
Correct |
56 ms |
94284 KB |
Output is correct |
3 |
Correct |
47 ms |
94248 KB |
Output is correct |
4 |
Correct |
46 ms |
94260 KB |
Output is correct |
5 |
Correct |
46 ms |
94388 KB |
Output is correct |
6 |
Correct |
47 ms |
94424 KB |
Output is correct |
7 |
Correct |
46 ms |
94356 KB |
Output is correct |
8 |
Correct |
54 ms |
94372 KB |
Output is correct |
9 |
Correct |
48 ms |
94380 KB |
Output is correct |
10 |
Correct |
47 ms |
94464 KB |
Output is correct |
11 |
Correct |
48 ms |
94420 KB |
Output is correct |
12 |
Correct |
47 ms |
94488 KB |
Output is correct |
13 |
Correct |
47 ms |
94492 KB |
Output is correct |
14 |
Correct |
46 ms |
94384 KB |
Output is correct |
15 |
Correct |
46 ms |
94276 KB |
Output is correct |
16 |
Correct |
47 ms |
94268 KB |
Output is correct |
17 |
Correct |
46 ms |
94376 KB |
Output is correct |
18 |
Correct |
46 ms |
94384 KB |
Output is correct |
19 |
Correct |
46 ms |
94364 KB |
Output is correct |
20 |
Correct |
51 ms |
94468 KB |
Output is correct |
21 |
Correct |
47 ms |
94492 KB |
Output is correct |
22 |
Correct |
47 ms |
94424 KB |
Output is correct |
23 |
Correct |
47 ms |
94536 KB |
Output is correct |
24 |
Correct |
47 ms |
94504 KB |
Output is correct |
25 |
Correct |
46 ms |
94472 KB |
Output is correct |
26 |
Correct |
46 ms |
94424 KB |
Output is correct |
27 |
Correct |
48 ms |
94288 KB |
Output is correct |
28 |
Correct |
49 ms |
94292 KB |
Output is correct |
29 |
Correct |
52 ms |
94412 KB |
Output is correct |
30 |
Correct |
48 ms |
94412 KB |
Output is correct |
31 |
Correct |
56 ms |
94468 KB |
Output is correct |
32 |
Correct |
49 ms |
94368 KB |
Output is correct |
33 |
Correct |
50 ms |
94488 KB |
Output is correct |
34 |
Correct |
51 ms |
94484 KB |
Output is correct |
35 |
Correct |
46 ms |
94400 KB |
Output is correct |
36 |
Correct |
46 ms |
94576 KB |
Output is correct |
37 |
Correct |
47 ms |
94384 KB |
Output is correct |
38 |
Correct |
55 ms |
94508 KB |
Output is correct |
39 |
Correct |
48 ms |
94800 KB |
Output is correct |
40 |
Correct |
48 ms |
94796 KB |
Output is correct |
41 |
Correct |
48 ms |
95052 KB |
Output is correct |
42 |
Correct |
57 ms |
95108 KB |
Output is correct |
43 |
Correct |
47 ms |
95052 KB |
Output is correct |
44 |
Correct |
48 ms |
95096 KB |
Output is correct |
45 |
Correct |
48 ms |
95100 KB |
Output is correct |
46 |
Correct |
48 ms |
95104 KB |
Output is correct |
47 |
Correct |
47 ms |
95116 KB |
Output is correct |
48 |
Correct |
48 ms |
95648 KB |
Output is correct |
49 |
Correct |
55 ms |
96060 KB |
Output is correct |
50 |
Correct |
48 ms |
96580 KB |
Output is correct |
51 |
Correct |
53 ms |
97100 KB |
Output is correct |
52 |
Correct |
50 ms |
97128 KB |
Output is correct |
53 |
Correct |
50 ms |
97108 KB |
Output is correct |
54 |
Correct |
53 ms |
97080 KB |
Output is correct |
55 |
Correct |
48 ms |
97136 KB |
Output is correct |
56 |
Correct |
50 ms |
95120 KB |
Output is correct |
57 |
Correct |
54 ms |
96060 KB |
Output is correct |
58 |
Correct |
52 ms |
96668 KB |
Output is correct |
59 |
Correct |
62 ms |
97128 KB |
Output is correct |
60 |
Correct |
51 ms |
97140 KB |
Output is correct |
61 |
Correct |
49 ms |
97140 KB |
Output is correct |
62 |
Correct |
52 ms |
97100 KB |
Output is correct |
63 |
Correct |
60 ms |
97176 KB |
Output is correct |
64 |
Correct |
75 ms |
96728 KB |
Output is correct |
65 |
Correct |
54 ms |
95128 KB |
Output is correct |
66 |
Correct |
59 ms |
95692 KB |
Output is correct |
67 |
Correct |
66 ms |
96204 KB |
Output is correct |
68 |
Correct |
76 ms |
96872 KB |
Output is correct |
69 |
Correct |
98 ms |
97352 KB |
Output is correct |
70 |
Correct |
104 ms |
97316 KB |
Output is correct |
71 |
Correct |
94 ms |
97304 KB |
Output is correct |
72 |
Correct |
84 ms |
97352 KB |
Output is correct |
73 |
Correct |
98 ms |
97344 KB |
Output is correct |
74 |
Correct |
93 ms |
97344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
94284 KB |
Output is correct |
2 |
Correct |
49 ms |
94304 KB |
Output is correct |
3 |
Correct |
47 ms |
94252 KB |
Output is correct |
4 |
Correct |
47 ms |
94284 KB |
Output is correct |
5 |
Correct |
49 ms |
94348 KB |
Output is correct |
6 |
Correct |
53 ms |
94504 KB |
Output is correct |
7 |
Correct |
47 ms |
94412 KB |
Output is correct |
8 |
Correct |
48 ms |
94420 KB |
Output is correct |
9 |
Correct |
48 ms |
94412 KB |
Output is correct |
10 |
Correct |
49 ms |
94488 KB |
Output is correct |
11 |
Correct |
47 ms |
94412 KB |
Output is correct |
12 |
Correct |
50 ms |
94488 KB |
Output is correct |
13 |
Correct |
49 ms |
94484 KB |
Output is correct |
14 |
Correct |
50 ms |
94384 KB |
Output is correct |
15 |
Correct |
52 ms |
94332 KB |
Output is correct |
16 |
Correct |
47 ms |
94328 KB |
Output is correct |
17 |
Correct |
47 ms |
94456 KB |
Output is correct |
18 |
Correct |
51 ms |
94380 KB |
Output is correct |
19 |
Correct |
48 ms |
94416 KB |
Output is correct |
20 |
Correct |
50 ms |
94452 KB |
Output is correct |
21 |
Correct |
48 ms |
94476 KB |
Output is correct |
22 |
Correct |
51 ms |
94480 KB |
Output is correct |
23 |
Correct |
49 ms |
94388 KB |
Output is correct |
24 |
Correct |
48 ms |
94412 KB |
Output is correct |
25 |
Correct |
46 ms |
94492 KB |
Output is correct |
26 |
Correct |
51 ms |
94696 KB |
Output is correct |
27 |
Correct |
48 ms |
94892 KB |
Output is correct |
28 |
Correct |
52 ms |
94996 KB |
Output is correct |
29 |
Correct |
55 ms |
95052 KB |
Output is correct |
30 |
Correct |
47 ms |
95104 KB |
Output is correct |
31 |
Correct |
46 ms |
95004 KB |
Output is correct |
32 |
Correct |
47 ms |
95052 KB |
Output is correct |
33 |
Correct |
48 ms |
95008 KB |
Output is correct |
34 |
Correct |
48 ms |
95052 KB |
Output is correct |
35 |
Correct |
48 ms |
95460 KB |
Output is correct |
36 |
Correct |
48 ms |
95968 KB |
Output is correct |
37 |
Correct |
49 ms |
96684 KB |
Output is correct |
38 |
Correct |
52 ms |
97224 KB |
Output is correct |
39 |
Correct |
51 ms |
97064 KB |
Output is correct |
40 |
Correct |
50 ms |
97144 KB |
Output is correct |
41 |
Correct |
54 ms |
97112 KB |
Output is correct |
42 |
Correct |
51 ms |
97068 KB |
Output is correct |
43 |
Correct |
49 ms |
95132 KB |
Output is correct |
44 |
Correct |
55 ms |
95964 KB |
Output is correct |
45 |
Correct |
63 ms |
96656 KB |
Output is correct |
46 |
Correct |
51 ms |
97096 KB |
Output is correct |
47 |
Correct |
51 ms |
97156 KB |
Output is correct |
48 |
Correct |
52 ms |
97100 KB |
Output is correct |
49 |
Correct |
56 ms |
97100 KB |
Output is correct |
50 |
Correct |
53 ms |
97148 KB |
Output is correct |
51 |
Correct |
60 ms |
97148 KB |
Output is correct |
52 |
Correct |
221 ms |
181040 KB |
Output is correct |
53 |
Correct |
377 ms |
240080 KB |
Output is correct |
54 |
Runtime error |
208 ms |
262144 KB |
Execution killed with signal 9 |
55 |
Halted |
0 ms |
0 KB |
- |