제출 #112121

#제출 시각아이디문제언어결과실행 시간메모리
112121toonewbieBali Sculptures (APIO15_sculpture)C++17
100 / 100
193 ms16284 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define F first
#define S second

const int N = 2006;
const int INF = 1e9;
const ll INFLL = 1e18;

int n, a, b;
int y[N];
ll p[N];
int dp[N][N], DP[N];

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) {
        cin >> y[i];
        p[i] = p[i - 1] + y[i];
    }
    if (n <= 100) {
        ll res = 0;
        for (int bt = 42; bt >= 0; bt--) {
            ll cur = (1LL << bt) | res;
            memset(dp, 0, sizeof(dp));
            for (int i = 1; i <= n; i++) {
                if ((p[i] & cur) == 0) {
                    dp[1][i] = 1;
                }
            }
            for (int j = 2; j <= n; j++) {
                for (int i = j; i <= n; i++) {
                    for (int k = j - 1; k < i; k++) {
                        ll last = p[i] - p[k];
                        if (dp[j - 1][k] == 1 && ((last & cur) == 0)) {
                            dp[j][i] = 1;
                            break;
                        }
                    }
                }
            }
            int ok = 1;
            for (int i = a; i <= b; i++) {
                if (dp[i][n]) {
                    res |= (1LL << bt);
                    break;
                }
            }
        }
        cout << (1LL << 43) - 1 - res << endl;
    } else {
        ll res = 0;
        for (int bt = 42; bt >= 0; bt--) {
            ll cur = (1LL << bt) | res;
            memset(DP, 63, sizeof(DP));
            DP[0] = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j < i; j++) {
                    ll last = p[i] - p[j];
                    if ((last & cur) == 0) {
                        DP[i] = min(DP[i], DP[j] + 1);
                    }
                }
            }
            if (DP[n] <= b) {
                res |= (1LL << bt);
            }
        }
        cout << (1LL << 43) - 1 - res << endl;
    }
    return 0;
}

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

sculpture.cpp: In function 'int main()':
sculpture.cpp:47:17: warning: unused variable 'ok' [-Wunused-variable]
             int ok = 1;
                 ^~
#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...