Submission #1115521

# Submission time Handle Problem Language Result Execution time Memory
1115521 2024-11-20T14:50:51 Z gdragon Bali Sculptures (APIO15_sculpture) C++17
9 / 100
33 ms 592 KB
#include <bits/stdc++.h>
using namespace std;
#define TASK "long"
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define GETBIT(mask, i) ((mask) >> (i) & 1)
#define MASK(i) ((1LL) << (i))
#define SZ(x) ((int)(x).size())
#define mp make_pair
#define CNTBIT(mask) __builtin_popcount(mask)
template<class X, class Y> bool maximize(X &x, Y y){ if (x < y) {x = y; return true;} return false;};
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y) {x = y; return true;} return false;};
typedef pair<int, int> ii;
const int N = 1e5 + 5;
const long long INF = (long long)1e18 + 7;
const int mod = 1e9 + 7;
int n, A, B;
vector<long long> f;
vector<vector<long long>> dp;
void read() {
    cin >> n >> A >> B;
    f.assign(n + 1, 0);
    for(int i = 1; i <= n; i++) {
        cin >> f[i];
        f[i] += f[i - 1];
    }
}
long long sum(int l, int r) {
    return f[r] - f[l - 1];
}
void sub1() {
    int m = n - 1;
    long long ans = INF;
    for(int mask = 0; mask < MASK(m); mask++) {
        if (CNTBIT(mask) + 1 > B || CNTBIT(mask) + 1 < A) continue;
        int pre = 1;
        long long res = 0;
        for(int i = 1; i < n; i++) if (GETBIT(mask, i - 1)) {
            res |= sum(pre, i);
            pre = i + 1;
        }
        res |= sum(pre, n);
        ans = min(ans, res);
    }
    cout << ans;
}
void solve() {
    if (n <= 20) {
        sub1();
        return;
    }
  return;
    dp.assign(n + 1, vector<long long>(B + 1, INF));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int k = 1; k <= min(B, i); k++) {
            for(int j = i - 1; j >= k - 1; j--) {
                if (dp[j][k - 1] == INF) continue;
                minimize(dp[i][k], (dp[j][k - 1] | sum(j + 1, i)));
            }
        }
    }
    long long ans = INF;    
    for(int k = A; k <= B; k++) ans = min(ans, dp[n][k]);
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
    int test = 1;
    // cin >> test;
    while(test--) {
        read();
        solve();
    }
    return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 31 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 500 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 4 ms 336 KB Output is correct
22 Correct 4 ms 592 KB Output is correct
23 Correct 4 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 4 ms 336 KB Output is correct
26 Correct 26 ms 440 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 26 ms 336 KB Output is correct
34 Correct 31 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 30 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 31 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 4 ms 336 KB Output is correct
22 Correct 4 ms 336 KB Output is correct
23 Correct 4 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 4 ms 336 KB Output is correct
26 Correct 26 ms 336 KB Output is correct
27 Incorrect 1 ms 504 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 452 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 31 ms 456 KB Output is correct
14 Incorrect 1 ms 336 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 31 ms 452 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 4 ms 336 KB Output is correct
22 Correct 4 ms 336 KB Output is correct
23 Correct 5 ms 456 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 4 ms 336 KB Output is correct
26 Correct 26 ms 456 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 4 ms 508 KB Output is correct
32 Correct 2 ms 424 KB Output is correct
33 Correct 26 ms 336 KB Output is correct
34 Correct 31 ms 336 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 33 ms 336 KB Output is correct
37 Incorrect 1 ms 336 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 32 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 4 ms 500 KB Output is correct
19 Correct 2 ms 552 KB Output is correct
20 Correct 26 ms 336 KB Output is correct
21 Correct 31 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 31 ms 336 KB Output is correct
24 Incorrect 1 ms 504 KB Output isn't correct
25 Halted 0 ms 0 KB -