Submission #708054

#TimeUsernameProblemLanguageResultExecution timeMemory
708054DennisTranBali Sculptures (APIO15_sculpture)C++17
46 / 100
570 ms262144 KiB
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }

using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) { return l + rnd() % (r - l + 1); }

const int MAXN = 2005;

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

struct SUB1{
    long long ans = 1e18;
    vector <int> lim;

    void check(int sz) {
        sz--;
        if (sz < L || sz > R) return;
        sz++;
        long long tmp = 0;
        for (int i = 1; i < sz; i++) {
            tmp |= (sum[lim[i]] - sum[lim[i - 1]]);
        }
        ans = min(ans, tmp);
    }

    void Try(int id) {
        if (id == N + 1) {
            if (lim.back() != N) return;
            return void(check(lim.size()));
        }
        Try(id + 1);
        lim.emplace_back(id);
        Try(id + 1);
        lim.pop_back();
    }

    void solve(void) {
        lim.emplace_back(0);
        Try(1);
        cout << ans; exit(0);
    }
} sub1;

struct SUB2{
    unordered_set <long long> dp[MAXN][MAXN];
    void solve(void) {
        dp[0][0].insert(0);
        REP(i, N) {
            REP(j, min(i + 1, R)) {
                for (long long x : dp[i][j]) {
                    FOR(nxt, i + 1, N)
                        dp[nxt][j + 1].insert(x | sum[nxt] - sum[i]);
                }
            }
        }
        long long ans = 1e18;
        FOR(i, L, R)
            for (long long x : dp[N][i]) ans = min(ans, x);
        cout << ans;
    }
} sub2;

signed main(void) {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    file("TASK");
    cin >> N >> L >> R;
    FOR(i, 1, N) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }

    if (N <= 20) sub1.solve();
    sub2.solve();
    cerr << "Time elapsed: " << TIME << " s.\n";
    return (0 ^ 0);
}

Compilation message (stderr)

sculpture.cpp: In member function 'void SUB2::solve()':
sculpture.cpp:61:60: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   61 |                         dp[nxt][j + 1].insert(x | sum[nxt] - sum[i]);
      |                                                   ~~~~~~~~~^~~~~~~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:9:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:74:5: note: in expansion of macro 'file'
   74 |     file("TASK");
      |     ^~~~
sculpture.cpp:9:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:74:5: note: in expansion of macro 'file'
   74 |     file("TASK");
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...