제출 #160175

#제출 시각아이디문제언어결과실행 시간메모리
160175BlueDiamondBali Sculptures (APIO15_sculpture)C++14
100 / 100
211 ms4344 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 2000 + 7;
int n, mn, mx, dp[N];
ll a[N];
bool good[N][N], ok[N][N];

bool okapi(ll x, ll cur, int bit)
{
        x -= x & cur;
        return (x < (1LL << bit));
}

bool valid(ll cur, int bit)
{
        ll val = (1LL << bit);

        for (int i = 1; i <= n; i++)
        {
                ll sum = 0;
                for (int j = i; j <= n; j++)
                {
                        sum += a[j];
                        good[i][j] = okapi(sum, cur, bit);
                }
        }

        if (mn == 1) {
                dp[0] = 0;
                for (int i = 1; i <= n; i++) {
                        dp[i] = (int) 1e9;
                        for (int j = 1; j <= i; j++)
                                if (good[j][i])
                                        dp[i] = min(dp[i], 1 + dp[j - 1]);
                }
                return (dp[n] <= mx);
        }

        for (int i = 0; i <= n; i++)
                for (int j = 0; j <= mx; j++)
                        ok[i][j] = 0;

        ok[0][0] = 1;
        for (int i = 0; i < n; i++)
                for (int c = 0; c < mx; c++)
                        if (ok[i][c])
                                for (int j = i + 1; j <= n; j++)
                                        if (good[i + 1][j])
                                                ok[j][c + 1] = 1;

        for (int c = mn; c <= mx; c++)
                if (ok[n][c])
                        return 1;
        return 0;
}

int main()
{
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

        ///     freopen ("input", "r", stdin);

        cin >> n >> mn >> mx;
        for (int i = 1; i <= n; i++)
                cin >> a[i];

        ll sum = 0;
        for (int i = 1; i <= n; i++)
                sum += a[i];

        ll mask = 0;
        for (int k = log2(sum); k >= 0; k--)
                if (valid(mask, k) == 0)
                        mask += (1LL << k);

        cout << mask << "\n";
        return 0;


        return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sculpture.cpp: In function 'bool valid(ll, int)':
sculpture.cpp:19:12: warning: unused variable 'val' [-Wunused-variable]
         ll val = (1LL << bit);
            ^~~
#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...