Submission #566561

# Submission time Handle Problem Language Result Execution time Memory
566561 2022-05-22T12:05:38 Z ac2hu Bali Sculptures (APIO15_sculpture) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else 
#define deb(x...)
#endif
using namespace std;
#define int long long 
struct node{
    vector<int> val;
    vector<int> minimal;
    void add(int x){
        for(int i = 0;i<(int)minimal.size();i++){
            if(minimal[i] == -1){
                minimal[i] = x;
            }
            else if((val[i]|x) < (val[i]|minimal[i])){
                minimal[i] = x;
            }
        }
    }
};
signed main() {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int n, a, b;cin >> n >> a >> b;
    vector<int> Y(n);
    for(auto &e : Y)cin >> e;
    node dp[n + 1][n + 1];
    for(int i = 0;i<n;i++){
        int tsum = Y[i];
        dp[i + 1][0].val.push_back(0);
        for(int j = i + 1;j<n;j++){
            dp[i + 1][0].val.push_back(tsum);
            tsum += Y[i];
        }
        dp[i + 1][0].minimal.resize(dp[i + 1][0].val.size(), -1);
        for(int j = 1;j<=n;j++)
            dp[i + 1][j] = dp[i + 1][j - 1];
    }
    for(int i = 0;i<=n;i++)
        dp[0][i] = dp[1][i];
    dp[0][0].add(0);
    vector<vector<int>> ans(n + 1, vector<int>(n + 1, 1e18));
    for(int i = 1;i<=n;i++){
        for(int gsize = 1;gsize<=n;gsize++){
            int tsum = 0;
            for(int j = i;j>=1;j--){
                tsum += Y[j - 1];
                for(auto e : dp[j - 1][gsize - 1].minimal){
                    if(e != -1){
                        dp[i][gsize].add(e|tsum);
                        ans[i][gsize] = min(ans[i][gsize], e|tsum);
                    }
                }
            }
        }
    }    
    int mn = 1e18;
    for(int i = a;i<=b;i++)
        mn = min(mn, ans[n][i]);
    cout << mn << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -