Submission #744189

# Submission time Handle Problem Language Result Execution time Memory
744189 2023-05-18T09:03:14 Z fanwen Bali Sculptures (APIO15_sculpture) C++17
100 / 100
61 ms 768 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()

#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define file(TASK)                         \
    if (fopen(TASK ".inp", "r")) {         \
        freopen(TASK ".inp", "r", stdin);  \
        freopen(TASK ".out", "w", stdout); \
    }

template <class U, class V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <class U, class V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

const int MAXN = 2e3 + 5;

int N, L, R, dp[MAXN][MAXN];
long long a[MAXN];

namespace sub1 {

    void Main() {
        long long ans = 0;
        FORD(bit, 40, 0) {
            long long mask = ans + MASK(bit) - 1;
            FOR(i, 0, N) FOR(x, 0, R) dp[i][x] = 0;
            dp[0][0] = 1;
            FOR(i, 1, N) FOR(j, 1, R) FOR(k, 1, i) {
                long long sum = a[i] - a[k - 1];
                if((sum & mask) == sum) dp[i][j] |= dp[k - 1][j - 1];
            }
            bool check = 0;
            FOR(i, L, R) check |= dp[N][i];
            if(check == 0) ans |= MASK(bit);
        }
        cout << ans;
        exit(0);
    }
}


namespace sub2 {

    void Main() {

        long long ans = 0;
        vector <int> F(N + 1);
        FORD(bit, 40, 0) {
            long long mask = ans + MASK(bit) - 1;
            fill(ALL(F), N + 1);
            F[0] = 0;
            FOR(i, 1, N) FOR(j, 1, i) {
                long long sum = a[i] - a[j - 1];
                if((sum & mask) == sum) minimize(F[i], F[j - 1] + 1);
            }
            if(F[N] > R) ans |= MASK(bit);
        }

        cout << ans; exit(0);
    }
}
void process(void) {

    cin >> N >> L >> R;

    FOR(i, 1, N) cin >> a[i], a[i] += a[i - 1];

    if(N <= 100) sub1::Main();
    sub2::Main();
}
signed main() {
    file("TASK");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) {
        process();
        cout << '\n';
    }
    cerr << "Time elapsed: " << TIME << " s.\n";
    return (0 ^ 0);
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen(TASK ".inp", "r", stdin);  \
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:81:5: note: in expansion of macro 'file'
   81 |     file("TASK");
      |     ^~~~
sculpture.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen(TASK ".out", "w", stdout); \
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:81:5: note: in expansion of macro 'file'
   81 |     file("TASK");
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 7 ms 596 KB Output is correct
27 Correct 17 ms 716 KB Output is correct
28 Correct 37 ms 760 KB Output is correct
29 Correct 38 ms 748 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 19 ms 752 KB Output is correct
32 Correct 28 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 280 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 3 ms 536 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 3 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 6 ms 596 KB Output is correct
50 Correct 17 ms 596 KB Output is correct
51 Correct 38 ms 724 KB Output is correct
52 Correct 37 ms 760 KB Output is correct
53 Correct 1 ms 724 KB Output is correct
54 Correct 18 ms 724 KB Output is correct
55 Correct 27 ms 724 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 5 ms 596 KB Output is correct
58 Correct 14 ms 708 KB Output is correct
59 Correct 28 ms 744 KB Output is correct
60 Correct 28 ms 724 KB Output is correct
61 Correct 1 ms 724 KB Output is correct
62 Correct 30 ms 724 KB Output is correct
63 Correct 33 ms 752 KB Output is correct
64 Correct 26 ms 596 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 2 ms 468 KB Output is correct
67 Correct 5 ms 596 KB Output is correct
68 Correct 13 ms 712 KB Output is correct
69 Correct 28 ms 724 KB Output is correct
70 Correct 28 ms 764 KB Output is correct
71 Correct 1 ms 724 KB Output is correct
72 Correct 30 ms 736 KB Output is correct
73 Correct 22 ms 756 KB Output is correct
74 Correct 21 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 536 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 6 ms 596 KB Output is correct
37 Correct 17 ms 712 KB Output is correct
38 Correct 36 ms 748 KB Output is correct
39 Correct 40 ms 756 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 20 ms 748 KB Output is correct
42 Correct 27 ms 764 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 5 ms 596 KB Output is correct
45 Correct 14 ms 712 KB Output is correct
46 Correct 28 ms 724 KB Output is correct
47 Correct 28 ms 744 KB Output is correct
48 Correct 1 ms 632 KB Output is correct
49 Correct 30 ms 768 KB Output is correct
50 Correct 30 ms 724 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 7 ms 340 KB Output is correct
53 Correct 9 ms 340 KB Output is correct
54 Correct 17 ms 352 KB Output is correct
55 Correct 15 ms 340 KB Output is correct
56 Correct 57 ms 348 KB Output is correct
57 Correct 56 ms 356 KB Output is correct
58 Correct 55 ms 352 KB Output is correct
59 Correct 57 ms 340 KB Output is correct
60 Correct 60 ms 340 KB Output is correct
61 Correct 1 ms 328 KB Output is correct
62 Correct 9 ms 340 KB Output is correct
63 Correct 18 ms 352 KB Output is correct
64 Correct 15 ms 340 KB Output is correct
65 Correct 29 ms 340 KB Output is correct
66 Correct 43 ms 344 KB Output is correct
67 Correct 56 ms 340 KB Output is correct
68 Correct 61 ms 352 KB Output is correct
69 Correct 57 ms 340 KB Output is correct