Submission #873744

# Submission time Handle Problem Language Result Execution time Memory
873744 2023-11-15T15:15:29 Z thienhx Bali Sculptures (APIO15_sculpture) C++17
100 / 100
68 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using ld = long double;
using db = double;

///--------------------------------

#define           F   first
#define           S   second
#define          pb   push_back
#define          lb   lower_bound
#define          ub   upper_bound
#define       sz(x)   (int)((x).size())
#define      all(x)   (x).begin(), (x).end()
#define     rall(x)   (x).rbegin(), (x).rend()
#define   mem(f, x)   memset(f, x, sizeof(f))
#define  uniqueV(x)   sort(all(x)), (x).resize(unique(all(x)) - x.begin())

template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }

///--------------------------------

#define PROBLEM "test"

const int MOD = 1e9 + 7; // 998244353;
const ll INF = 1e18;
const ld eps = 1e-9;
const ld PI = acos(-1);
const int dx[4]{0, 1, 0, -1}, dy[4]{1, 0, -1, 0}; // R D L U
const int ddx[4]{-1, 1, 1, -1}, ddy[4]{1, 1, -1, -1}; // UR DR DL UL

///--------------------------------

void precalc();
void solve();

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    if (fopen(PROBLEM".inp", "r")) {
        freopen(PROBLEM".inp", "r", stdin);
        freopen(PROBLEM".out", "w", stdout);
    }

    constexpr bool MULTI_TEST = 0;

    int t = 1;
    if (MULTI_TEST) cin >> t;

    while (t--)
        solve();
    
    // cerr << setprecision(3) << fixed;
    // cerr << "[" << 1.0 * clock() / CLOCKS_PER_SEC << "s]  ";
}

///--------------------[PROBLEM SOLUTION]--------------------///

const int LOG = 40;
const int maxn = 2020;
bool dp[107][107];
ll v[maxn], dp2[maxn];

bool match(ll mask, ll suf, ll p) {
    return (((mask >> p << p) | suf) == suf);
}

void solve() {
    ll n, A, B;
    cin >> n >> A >> B;

    for (int i = 1; i <= n; i++)
        cin >> v[i];

    if (n <= 100) {
        ll suf = 0;
        for (int j = LOG; j >= 0; j--) {
            mem(dp, false);
            dp[0][0] = true;

            for (int i = 1; i <= n; i++) {
                for (int k = 1; k <= i; k++) {
                    ll sum = 0;
                    for (int h = i; h >= 1; h--) {
                        sum += v[h];

                        if (match(sum, suf, j))
                            dp[i][k] |= dp[h - 1][k - 1];
                    }
                }
            }

            bool check = false;
            for (int i = A; i <= B; i++)
                if (dp[n][i])
                    check = true;

            if (!check) 
                suf += (1LL << j);
        }

        cout << suf << '\n';
    }   
    else {
        ll suf = 0;
        for (int j = LOG; j >= 0; j--) {
            mem(dp2, 0x3f);
            dp2[0] = 0;
            
            for (int i = 1; i <= n; i++) {
                ll sum = 0;
                for (int h = i; h >= 1; h--) {
                    sum += v[h];
                    
                    if (match(sum, suf, j))
                        minimize(dp2[i], dp2[h - 1] + 1);
                }
            }

            if (dp2[n] > B)
                suf += (1LL << j);
        }

        cout << suf << '\n';
    } 
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(PROBLEM".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen(PROBLEM".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 504 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 500 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 3 ms 344 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 472 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 3 ms 468 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 6 ms 472 KB Output is correct
26 Correct 11 ms 600 KB Output is correct
27 Correct 18 ms 472 KB Output is correct
28 Correct 24 ms 468 KB Output is correct
29 Correct 24 ms 348 KB Output is correct
30 Correct 25 ms 472 KB Output is correct
31 Correct 25 ms 344 KB Output is correct
32 Correct 25 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 360 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 472 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 3 ms 348 KB Output is correct
42 Correct 3 ms 348 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 4 ms 348 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Correct 3 ms 348 KB Output is correct
47 Correct 3 ms 348 KB Output is correct
48 Correct 6 ms 348 KB Output is correct
49 Correct 11 ms 468 KB Output is correct
50 Correct 19 ms 468 KB Output is correct
51 Correct 24 ms 468 KB Output is correct
52 Correct 24 ms 472 KB Output is correct
53 Correct 25 ms 348 KB Output is correct
54 Correct 25 ms 348 KB Output is correct
55 Correct 25 ms 348 KB Output is correct
56 Correct 3 ms 348 KB Output is correct
57 Correct 9 ms 348 KB Output is correct
58 Correct 13 ms 348 KB Output is correct
59 Correct 21 ms 348 KB Output is correct
60 Correct 18 ms 348 KB Output is correct
61 Correct 18 ms 348 KB Output is correct
62 Correct 18 ms 472 KB Output is correct
63 Correct 18 ms 348 KB Output is correct
64 Correct 19 ms 472 KB Output is correct
65 Correct 3 ms 348 KB Output is correct
66 Correct 5 ms 348 KB Output is correct
67 Correct 8 ms 344 KB Output is correct
68 Correct 13 ms 472 KB Output is correct
69 Correct 19 ms 604 KB Output is correct
70 Correct 17 ms 348 KB Output is correct
71 Correct 18 ms 600 KB Output is correct
72 Correct 18 ms 472 KB Output is correct
73 Correct 18 ms 472 KB Output is correct
74 Correct 18 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 404 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 3 ms 472 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 7 ms 348 KB Output is correct
36 Correct 11 ms 348 KB Output is correct
37 Correct 19 ms 468 KB Output is correct
38 Correct 25 ms 348 KB Output is correct
39 Correct 24 ms 472 KB Output is correct
40 Correct 25 ms 348 KB Output is correct
41 Correct 25 ms 600 KB Output is correct
42 Correct 25 ms 348 KB Output is correct
43 Correct 3 ms 472 KB Output is correct
44 Correct 9 ms 348 KB Output is correct
45 Correct 14 ms 500 KB Output is correct
46 Correct 17 ms 348 KB Output is correct
47 Correct 17 ms 348 KB Output is correct
48 Correct 18 ms 348 KB Output is correct
49 Correct 18 ms 604 KB Output is correct
50 Correct 18 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 6 ms 348 KB Output is correct
53 Correct 10 ms 600 KB Output is correct
54 Correct 18 ms 496 KB Output is correct
55 Correct 17 ms 344 KB Output is correct
56 Correct 64 ms 348 KB Output is correct
57 Correct 64 ms 344 KB Output is correct
58 Correct 62 ms 348 KB Output is correct
59 Correct 62 ms 348 KB Output is correct
60 Correct 65 ms 492 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 10 ms 348 KB Output is correct
63 Correct 19 ms 348 KB Output is correct
64 Correct 17 ms 348 KB Output is correct
65 Correct 34 ms 480 KB Output is correct
66 Correct 49 ms 488 KB Output is correct
67 Correct 66 ms 344 KB Output is correct
68 Correct 68 ms 492 KB Output is correct
69 Correct 64 ms 348 KB Output is correct