제출 #45855

#제출 시각아이디문제언어결과실행 시간메모리
45855ExtazyBali Sculptures (APIO15_sculpture)C++17
37 / 100
1085 ms1052 KiB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 2007;

int n,a,b;
long long arr[N];
long long ans;
long long val;
bool used[N][N],state[N][N];

bool recurse(int pos, int groups) {
    if(pos>n) return a<=groups && groups<=b;
    
    if(used[pos][groups]) return state[pos][groups];
    
    used[pos][groups]=true;

    int i;
    long long sum=0;

    for(i=pos;i<=n;i++) {
        sum+=arr[i];
        //if(sum>val) break;
        if((sum&val)==sum) if(recurse(i+1,groups+1)) return state[pos][groups]=true;
    }

    return state[pos][groups]=false;
}

bool can(long long x) {
    int i,j;

    val=x;
    
    for(i=1;i<=n;i++) {
        for(j=0;j<=n;j++) {
            used[i][j]=false;
        }
    }

    return recurse(1,0);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i;

    scanf("%d %d %d", &n, &a, &b);
    for(i=1;i<=n;i++) {
        scanf("%lld", &arr[i]);
    }

    ans=0;
    while(!can(ans)) ++ans;
    /*while(!can(ans)) {
        for(i=0;i<40;i++) {
            if(ans&(1ll<<i)) break;
            if(can(ans|(1ll<<i))) {
                ans|=(1ll<<i);
                break;
            }
        }
    }*/

    printf("%lld\n", ans);
    
    return 0;
}

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

sculpture.cpp: In function 'int main()':
sculpture.cpp:52: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:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~~~
#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...