Submission #884576

# Submission time Handle Problem Language Result Execution time Memory
884576 2023-12-07T17:14:47 Z AnhPham Bali Sculptures (APIO15_sculpture) C++17
16 / 100
18 ms 1628 KB
#include <bits/stdc++.h>

#ifdef OP_DEBUG
    #include <algo/debug.h>
#else
    #define debug(...) 26
#endif

using namespace std;

#define int 	long long // maybe tle?
#define sz(v)   (int)(v).size()
#define all(v)  (v).begin(), (v).end()
#define TcT     template <class T

const   int     MOD = (int)1e9 + 7, INF = (int)2e9 + 9, INF64 = (int)4e18 + 18;

TcT>            bool minimize(T &lhs, const T &rhs) { return rhs < lhs ? lhs = rhs, 1 : 0; }
TcT>            bool maximize(T &lhs, const T &rhs) { return rhs > lhs ? lhs = rhs, 1 : 0; }

TcT, class S>   istream &operator >> (istream &scanf, pair <T, S> &u) { return scanf >> u.first >> u.second;        }
TcT, class S>   ostream &operator << (ostream &print, pair <T, S> &u) { return print << u.first << ' ' << u.second; }

void solve();

int32_t main() {
    cin.tie(nullptr), cout.tie(nullptr) -> sync_with_stdio(0);
    int testcases = 1;

#define TC 0
    if (TC) { cin >> testcases; } for (; testcases--;) { solve(); }
}

/* [Pham Hung Anh - 11I - Tran Hung Dao High School for Gifted Student] */

const int N = 2002;

int n, a, b;
int y[N];

namespace sub1 {
    int ans = INF;
    void Try(int k, int parts, int sum, int sum_or) {
        if (k > n) {
            if (a <= parts && parts <= b)
                minimize(ans, sum_or | sum);

            return;
        }
        
        Try(k + 1, parts, sum + y[k], sum_or);
        Try(k + 1, parts + 1, y[k], sum_or | sum);
    }
    
    void solve() {
        Try(2, 1, y[1], 0);

        cout << ans << '\n';
    }
}

namespace sub2 {
    // max ans = 500?
    bool dp[55][22][505]; // xét đến i, đoạn thứ parts, tổng or là sum_or
    void solve() {
        dp[0][0][0] = 1;
        for (int i = 1; i <= n; ++i)
            for (int parts = 0; parts <= b; ++parts)
                for (int sum_or = 0; sum_or <= 500; ++sum_or) {
                    int sum = 0;
                    for (int j = i; j >= 1; --j)
                        dp[i][parts + 1][sum_or | (sum += y[j])] |= dp[j - 1][parts][sum_or];
                }

        int ans = INF;
        for (int parts = a; parts <= b; ++parts)
            for (int sum_or = 0; sum_or <= 500; ++sum_or)
                if (dp[n][parts][sum_or])
                    minimize(ans, sum_or);

        cout << ans << '\n';
    }
}

void solve() {
    cin >> n >> a >> b;

    for (int i = 1; i <= n; ++i)
        cin >> y[i];
    
    // if (n <= 20)
    //     sub1 :: solve();
    // else if (n <= 50)
        sub2 :: solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 352 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 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 3 ms 644 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 3 ms 604 KB Output is correct
27 Runtime error 1 ms 604 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# 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 2 ms 536 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 3 ms 604 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 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 4 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 3 ms 620 KB Output is correct
30 Correct 10 ms 860 KB Output is correct
31 Correct 15 ms 992 KB Output is correct
32 Correct 14 ms 996 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 15 ms 860 KB Output is correct
35 Correct 13 ms 904 KB Output is correct
36 Correct 8 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 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 1 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 608 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 10 ms 860 KB Output is correct
18 Correct 16 ms 860 KB Output is correct
19 Correct 18 ms 860 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 15 ms 836 KB Output is correct
22 Correct 13 ms 856 KB Output is correct
23 Correct 8 ms 860 KB Output is correct
24 Correct 15 ms 896 KB Output is correct
25 Runtime error 11 ms 1628 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# 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 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 500 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Runtime error 1 ms 604 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Runtime error 1 ms 604 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -