답안 #883365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883365 2023-12-05T08:18:40 Z SalihSahin Bali Sculptures (APIO15_sculpture) C++14
0 / 100
1 ms 452 KB
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
 
using namespace std;
const int inf = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

int bf(int n, int a, int b, vector<int> &arr){
    int ans = inf;
    int par = 0;
    for(int j = 1; j < (1 << n); j += 2){
        int g = 0, val = 0, sum = 0;
        for(int i = 0; i < n; i++){
            if(j & (1 << i)){
                val |= sum;
                sum = 0;
                g++;
            }
            sum += arr[i];
        }
        val |= sum;
        if(g >= a && g <= b){
            ans = min(ans, val);
            par = j;
        }
    }
    return ans;
}

int dpp(int n, int a, int b, vector<int> &arr){
    int dp[n+1][n+1];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    vector<int> pre(n+1);
    for(int i = 1; i <= n; i++){
        pre[i] = pre[i-1] + arr[i-1];
    }
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = i + 1; k <= n; k++){
                dp[k][j+1] = min(dp[k][j+1], dp[i][j]|(pre[k] - pre[i]));
            }
        }
    }
 
    int ans2 = inf;
    for(int i = a; i <= b; i++){
        //cout<<i<<" "<<dp[n][i]<<endl;
        ans2 = min(ans2, dp[n][i]);
    }

    return ans2;
}

int32_t main(){
    ios_base::sync_with_stdio(false), cin.tie();
    int n, a, b;
    cin>>n>>a>>b;
    vector<int> arr(n);
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    cout<<dpp(n, a, b, arr)<<endl;
    return 0;
}

Compilation message

sculpture.cpp: In function 'long long int bf(long long int, long long int, long long int, std::vector<long long int>&)':
sculpture.cpp:13:9: warning: variable 'par' set but not used [-Wunused-but-set-variable]
   13 |     int par = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 452 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -