Submission #799191

# Submission time Handle Problem Language Result Execution time Memory
799191 2023-07-31T10:39:27 Z RecursiveCo Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 ms 444 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);
    
    // 71 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;
        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;
                    }
                }
            }
        }
        bool can = false;
        for (int i = A; i <= B; i++) {
            if (dp[n - 1][i]) {
                can = true;
                break;
            }
        }
        if (!can) ans += power;

        power >>= 1ll;
    }
    out(ans);
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
sculpture.cpp:23:5: note: in expansion of macro 'get'
   23 |     get(n);
      |     ^~~
sculpture.cpp:10:23: warning: unnecessary parentheses in declaration of 'A' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
sculpture.cpp:24:5: note: in expansion of macro 'get'
   24 |     get(A);
      |     ^~~
sculpture.cpp:10:23: warning: unnecessary parentheses in declaration of 'B' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
sculpture.cpp:25:5: note: in expansion of macro 'get'
   25 |     get(B);
      |     ^~~
sculpture.cpp:12:40: warning: unnecessary parentheses in declaration of 'nums' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
sculpture.cpp:26:5: note: in expansion of macro 'getList'
   26 |     getList(n, nums);
      |     ^~~~~~~
sculpture.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
sculpture.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
sculpture.cpp:26:5: note: in expansion of macro 'getList'
   26 |     getList(n, nums);
      |     ^~~~~~~
sculpture.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
sculpture.cpp:39:9: note: in expansion of macro 'forto'
   39 |         forto(n, i) {
      |         ^~~~~
sculpture.cpp:15:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
sculpture.cpp:41:13: note: in expansion of macro 'forto'
   41 |             forto(n + 1, j) {
      |             ^~~~~
# 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 1 ms 212 KB Output is correct
6 Correct 1 ms 324 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 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 1 ms 224 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 324 KB Output is correct
19 Correct 1 ms 368 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 316 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 320 KB Output is correct
29 Correct 1 ms 232 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 444 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 316 KB Output is correct
35 Correct 1 ms 320 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 1 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 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 212 KB Output is correct
11 Correct 1 ms 324 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 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 324 KB Output is correct
20 Correct 1 ms 316 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 296 KB Output is correct
24 Correct 1 ms 324 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 316 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 324 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 2 ms 316 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 2 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 1 ms 320 KB Output is correct
5 Correct 1 ms 340 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 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 316 KB Output is correct
21 Correct 2 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 2 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 3 ms 212 KB Output is correct
28 Correct 6 ms 316 KB Output is correct
29 Correct 4 ms 324 KB Output is correct
30 Correct 3 ms 212 KB Output is correct
31 Correct 4 ms 212 KB Output is correct
32 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 224 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 232 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 0 ms 320 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 1 ms 320 KB Output is correct
29 Correct 1 ms 316 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 316 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 1 ms 212 KB Output is correct
38 Correct 1 ms 212 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 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 2 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 2 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 320 KB Output is correct
53 Correct 3 ms 212 KB Output is correct
54 Correct 4 ms 212 KB Output is correct
55 Correct 7 ms 320 KB Output is correct
56 Correct 4 ms 212 KB Output is correct
57 Correct 6 ms 212 KB Output is correct
58 Correct 9 ms 324 KB Output is correct
59 Correct 12 ms 324 KB Output is correct
60 Correct 15 ms 320 KB Output is correct
61 Correct 18 ms 212 KB Output is correct
62 Correct 12 ms 328 KB Output is correct
63 Correct 13 ms 212 KB Output is correct
64 Correct 2 ms 324 KB Output is correct
65 Correct 2 ms 212 KB Output is correct
66 Correct 6 ms 212 KB Output is correct
67 Correct 6 ms 212 KB Output is correct
68 Correct 11 ms 212 KB Output is correct
69 Correct 12 ms 328 KB Output is correct
70 Correct 13 ms 320 KB Output is correct
71 Correct 12 ms 212 KB Output is correct
72 Correct 12 ms 212 KB Output is correct
73 Correct 12 ms 320 KB Output is correct
74 Correct 12 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 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 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 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 320 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 2 ms 320 KB Output is correct
30 Correct 2 ms 328 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 2 ms 280 KB Output is correct
35 Correct 2 ms 212 KB Output is correct
36 Correct 4 ms 212 KB Output is correct
37 Correct 3 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 3 ms 212 KB Output is correct
41 Correct 4 ms 320 KB Output is correct
42 Correct 4 ms 324 KB Output is correct
43 Correct 3 ms 320 KB Output is correct
44 Correct 7 ms 212 KB Output is correct
45 Correct 9 ms 212 KB Output is correct
46 Correct 12 ms 328 KB Output is correct
47 Correct 15 ms 328 KB Output is correct
48 Correct 13 ms 324 KB Output is correct
49 Correct 12 ms 324 KB Output is correct
50 Correct 12 ms 324 KB Output is correct
51 Correct 13 ms 328 KB Output is correct
52 Execution timed out 1066 ms 328 KB Time limit exceeded
53 Halted 0 ms 0 KB -