# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
799206 | 2023-07-31T10:44:32 Z | RecursiveCo | Bali Sculptures (APIO15_sculpture) | C++14 | 142 ms | 1016 KB |
// CF template, version 3.0 #include <bits/stdc++.h> using namespace std; #define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0) #define getTest int t; cin >> t #define eachTest for (int _var=0;_var<t;_var++) #define get(name) int (name); cin >> (name) #define out(o) cout << (o) #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); } #define sortl(name) sort((name).begin(), (name).end()) #define rev(name) reverse((name).begin(), (name).end()) #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++) #define decision(b) if (b){out("YES");}else{out("NO");} #define int long long int signed main() { improvePerformance; get(n); get(A); get(B); getList(n, nums); // 100 points int ans = 0; int power = 1ll << 59ll; for (int b = 59; b >= 0; b--) { // DP with O(n2) states and O(n) transition per state. // so O(n3) DP // should be fine right? int lower = ans; int upper = ans + power - 1; vector<vector<bool>> dp(n, vector<bool>(n + 1, false)); int pref = 0; bool can = false; if (n <= 100) { // Naive DP forto(n, i) { pref += nums[i]; forto(n + 1, j) { if (j == 0) continue; if (j == 1) { dp[i][j] = lower <= (pref | ans) && (pref | ans) <= upper; continue; } if (j > i + 1) { dp[i][j] = false; break; } int sum = 0; for (int k = i - 1; k >= 0; k--) { sum += nums[k + 1]; if (dp[k][j - 1] && lower <= (sum | ans) && (sum | ans) <= upper) { dp[i][j] = true; break; } } } } for (int i = A; i <= B; i++) { if (dp[n - 1][i]) { can = true; break; } } } else { // A=1 since n is higher // we are interested in the "minimum number of groups we need." vector<int> dp(n, 1e18); int pref = 0; forto(n, i) { pref += nums[i]; int sum = 0; for (int k = i - 1; k >= 0; k--) { sum += nums[k + 1]; if (lower <= (sum | ans) && (sum | ans) <= upper) { dp[i] = min(dp[i], dp[k] + 1); } } if (lower <= (pref | ans) && (pref | ans) <= upper) dp[i] = 1; } if (dp[n - 1] <= B) can = true; } if (!can) ans += power; power >>= 1ll; } out(ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 316 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 320 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 320 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 324 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 1 ms | 320 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 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 | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 320 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 316 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 320 KB | Output is correct |
18 | Correct | 0 ms | 324 KB | Output is correct |
19 | Correct | 1 ms | 320 KB | Output is correct |
20 | Correct | 1 ms | 324 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 316 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 2 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 2 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 1 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 320 KB | Output is correct |
3 | Correct | 0 ms | 212 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 324 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 320 KB | Output is correct |
13 | Correct | 1 ms | 316 KB | Output is correct |
14 | Correct | 1 ms | 320 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 320 KB | Output is correct |
17 | Correct | 1 ms | 324 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 2 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 3 ms | 324 KB | Output is correct |
26 | Correct | 2 ms | 320 KB | Output is correct |
27 | Correct | 3 ms | 212 KB | Output is correct |
28 | Correct | 6 ms | 320 KB | Output is correct |
29 | Correct | 4 ms | 212 KB | Output is correct |
30 | Correct | 3 ms | 212 KB | Output is correct |
31 | Correct | 4 ms | 212 KB | Output is correct |
32 | Correct | 7 ms | 320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 1 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 | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 1 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 0 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 320 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 1 ms | 212 KB | Output is correct |
41 | Correct | 1 ms | 232 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 2 ms | 212 KB | Output is correct |
44 | Correct | 1 ms | 320 KB | Output is correct |
45 | Correct | 1 ms | 320 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 2 ms | 212 KB | Output is correct |
49 | Correct | 3 ms | 212 KB | Output is correct |
50 | Correct | 3 ms | 212 KB | Output is correct |
51 | Correct | 4 ms | 212 KB | Output is correct |
52 | Correct | 4 ms | 212 KB | Output is correct |
53 | Correct | 3 ms | 212 KB | Output is correct |
54 | Correct | 4 ms | 212 KB | Output is correct |
55 | Correct | 5 ms | 212 KB | Output is correct |
56 | Correct | 2 ms | 212 KB | Output is correct |
57 | Correct | 8 ms | 328 KB | Output is correct |
58 | Correct | 9 ms | 332 KB | Output is correct |
59 | Correct | 12 ms | 212 KB | Output is correct |
60 | Correct | 23 ms | 212 KB | Output is correct |
61 | Correct | 12 ms | 332 KB | Output is correct |
62 | Correct | 12 ms | 332 KB | Output is correct |
63 | Correct | 12 ms | 212 KB | Output is correct |
64 | Correct | 2 ms | 212 KB | Output is correct |
65 | Correct | 2 ms | 212 KB | Output is correct |
66 | Correct | 4 ms | 212 KB | Output is correct |
67 | Correct | 6 ms | 212 KB | Output is correct |
68 | Correct | 11 ms | 320 KB | Output is correct |
69 | Correct | 13 ms | 324 KB | Output is correct |
70 | Correct | 14 ms | 332 KB | Output is correct |
71 | Correct | 14 ms | 324 KB | Output is correct |
72 | Correct | 13 ms | 328 KB | Output is correct |
73 | Correct | 16 ms | 212 KB | Output is correct |
74 | Correct | 19 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 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 | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 316 KB | Output is correct |
10 | Correct | 1 ms | 320 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 216 KB | Output is correct |
13 | Correct | 1 ms | 216 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 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 | 1 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 316 KB | Output is correct |
23 | Correct | 1 ms | 320 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 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 | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 2 ms | 212 KB | Output is correct |
35 | Correct | 2 ms | 324 KB | Output is correct |
36 | Correct | 2 ms | 212 KB | Output is correct |
37 | Correct | 4 ms | 212 KB | Output is correct |
38 | Correct | 4 ms | 212 KB | Output is correct |
39 | Correct | 4 ms | 212 KB | Output is correct |
40 | Correct | 4 ms | 288 KB | Output is correct |
41 | Correct | 6 ms | 212 KB | Output is correct |
42 | Correct | 4 ms | 212 KB | Output is correct |
43 | Correct | 2 ms | 212 KB | Output is correct |
44 | Correct | 7 ms | 212 KB | Output is correct |
45 | Correct | 10 ms | 328 KB | Output is correct |
46 | Correct | 12 ms | 212 KB | Output is correct |
47 | Correct | 14 ms | 212 KB | Output is correct |
48 | Correct | 12 ms | 328 KB | Output is correct |
49 | Correct | 13 ms | 324 KB | Output is correct |
50 | Correct | 12 ms | 328 KB | Output is correct |
51 | Correct | 1 ms | 220 KB | Output is correct |
52 | Correct | 12 ms | 320 KB | Output is correct |
53 | Correct | 22 ms | 456 KB | Output is correct |
54 | Correct | 55 ms | 528 KB | Output is correct |
55 | Correct | 37 ms | 524 KB | Output is correct |
56 | Correct | 133 ms | 988 KB | Output is correct |
57 | Correct | 136 ms | 980 KB | Output is correct |
58 | Correct | 132 ms | 1016 KB | Output is correct |
59 | Correct | 140 ms | 992 KB | Output is correct |
60 | Correct | 142 ms | 980 KB | Output is correct |
61 | Correct | 1 ms | 212 KB | Output is correct |
62 | Correct | 31 ms | 384 KB | Output is correct |
63 | Correct | 46 ms | 528 KB | Output is correct |
64 | Correct | 55 ms | 528 KB | Output is correct |
65 | Correct | 71 ms | 716 KB | Output is correct |
66 | Correct | 112 ms | 832 KB | Output is correct |
67 | Correct | 133 ms | 980 KB | Output is correct |
68 | Correct | 136 ms | 980 KB | Output is correct |
69 | Correct | 132 ms | 964 KB | Output is correct |