제출 #109857

#제출 시각아이디문제언어결과실행 시간메모리
109857PeppaPigBali Sculptures (APIO15_sculpture)C++14
100 / 100
473 ms4352 KiB
#include <bits/stdc++.h>
 
#define long long long
 
using namespace std;
 
const int N = 2e3+5;
 
int n, A, B;
long pref[N];
bool C[N][N];
 
int main() {
    scanf("%d %d %d", &n, &A, &B);
    for(int i = 1; i <= n; i++) scanf("%lld", pref+i), pref[i] += pref[i-1];
 
    if(A == 1) {
        long ans = 0;
        for(int b = 62; ~b; b--) {
            int dp[N]; fill_n(dp, N, 1e9);
            dp[0] = 0;
            for(int i = 1; i <= n; i++) for(int j = i; j <= n; j++) {
                long sum = pref[j] - pref[i-1];
                if(!(sum >> b & 1) && ((sum | ans) >> (b + 1)) == (ans >> (b + 1)))
                    dp[j] = min(dp[j], dp[i-1] + 1);
            }
            if(dp[n] > B) ans |= 1ll << b;
        }
        printf("%lld\n", ans);
    } else {
        long ans = 0;
        for(int b = 62; ~b; b--) {
            memset(C, false, sizeof C);
            C[0][0] = true;
            for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = i; j <= n; j++) {
                long sum = pref[j] - pref[i-1];
                if(!(sum >> b & 1) && ((sum | ans) >> (b + 1)) == (ans >> (b + 1)))
                    C[j][k] |= C[i-1][k-1];
            }
            bool valid = false;
            for(int i = A; i <= B; i++) valid |= C[n][i];
            if(!valid) ans |= 1ll << b;
        }
        printf("%lld\n", ans);
    }
 
    return 0;
}

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

sculpture.cpp: In function 'int main()':
sculpture.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &A, &B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:15:54: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%lld", pref+i), pref[i] += pref[i-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...