Submission #469399

#TimeUsernameProblemLanguageResultExecution timeMemory
469399chienyu_xiongBali Sculptures (APIO15_sculpture)C++17
21 / 100
5 ms332 KiB
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second

#define pb push_back
#define mp make_pair

#define int long long

#define pii pair<int, int>

#define all(_) begin(_), end(_)

#define smx(y, x) ((y) = max(x, y))
#define smn(y, x) ((y) = min(x, y))

void setIO() {
    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);
    cout.tie(nullptr);
}

const int N = 2e3 + 5;
const int M = 1e1 + 2;
const int K = 3e5 + 0;

const int inf = 9e17;
const int mod = 1e9 + 7; 

int xyz = 1; // test cases

int n, t, m;

int arr[N];

bool dp[2][N];

bool chk(int msk) {
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
        dp[0][i] = 0;

    for (int j = 1; j <= m; j++) {
        int p = j & 1;
        int o = p ^ 1;

        for (int i = 1; i <= n; i++) {
            int sum = 0;

            dp[p][i] = false;
            for (int k = i; k >= 1; k--)
                sum += arr[k], dp[p][i] |= (sum & msk) == sum && dp[o][k - 1];
        }

        if (j >= t && dp[p][n]) return true;

        /* for (int i = 1; i <= n; i++) cout << dp[p][i] << " "; cout << endl; */
    }

    return false;
}

void run() {
    cin >> n >> t >> m;

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

    int msk = (1 << 30) - 1;
    for (int i = 29; i >= 0; i--) {
        if (chk(msk ^ (1 << i))) {
            msk ^= (1 << i);
        }
    }

    cout << msk << endl;
}

signed main() {
    setIO();

    while (xyz--)
        run();

#ifdef LOCAL
    cin.clear(); cout.flush(); system("pause");
#endif

    return 0;
}
#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...