Submission #718315

# Submission time Handle Problem Language Result Execution time Memory
718315 2023-04-03T20:35:49 Z Urvuk3 Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 272 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define pb push_back

void PRINT(int x) {cerr << x;}
void PRINT(ll x) {cerr << x;}
void PRINT(double x) {cerr << x;}
void PRINT(char x) {cerr << '\'' << x << '\'';}
void PRINT(string x) {cerr << '\"' << x << '\"';}
void PRINT(bool x) {cerr << (x ? "true" : "false");}

template<typename T,typename V>
void PRINT(pair<T,V>& x){
    cerr<<"{";
    PRINT(x.fi);
    cerr<<",";
    PRINT(x.se);
    cerr<<"}";
}
template<typename T>
void PRINT(T &x){
    int id=0;
    cerr<<"{";
    for(auto _i:x){
        cerr<<(id++ ? "," : "");
        PRINT(_i);
    }
    cerr<<"}";
}
void _PRINT(){
    cerr<<"]\n";
}
template<typename Head,typename... Tail>
void _PRINT(Head h,Tail... t){
    PRINT(h);
    if(sizeof...(t)) cerr<<", ";
    _PRINT(t...);
}

#define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x)

void Solve(){
    int N,A,B; cin>>N>>A>>B;
    vector<ll> a(N+1);
    for(int i=1;i<=N;i++) cin>>a[i];
    vector<ll> pref(N+1,0);
    for(int i=1;i<=N;i++) pref[i]=pref[i-1]+a[i];
    if(N>2000){
        ll res=0;
        set<int> nparts;
        for(int i=A;i<=B;i++) nparts.insert(i);
        ll cur=0;
        for(ll bit=41;bit>=0;bit--){
            vector<vector<int>> dp(N+1,vector<int>(B+1,0));
            dp[0][0]=1;
            for(int i=1;i<=N;i++){
                for(int p=1;p<=min(i,B);p++){
                    for(int j=0;j<i;j++){
                        bool sb=(((pref[i]-pref[j])&((1LL<<bit)|cur))==0);
                        if(sb && dp[j][p-1]){
                            dp[i][p]=1;
                        }
                    }
                }
            }
            set<int> s;
            for(int p=1;p<=B;p++){
                if(dp[N][p] && nparts.count(p)){
                    s.insert(p);
                }
            }
            if(!s.empty()){
                nparts=s;
                cur+=(1LL<<bit);
            }
            else{
                res+=(1LL<<bit);
            }
        }
        cout<<res<<endl;
    }
    else{
        ll res=0;
        ll cur=0;
        for(ll bit=41;bit>=0;bit--){
            vector<int> dp(N+1,INF);
            dp[0]=0;
            for(int i=1;i<=N;i++){
                for(int j=0;j<i;j++){
                    if(j==0){
                        bool sb=(((pref[i]-pref[j])&((1LL<<bit)|cur))==0);
                        if(sb) dp[i]=0;
                    }
                    else{
                        bool sb=(((pref[i]-pref[j])&((1LL<<bit)|cur))==0);
                        if(sb){
                            dp[i]=min(dp[i],dp[j]+1);
                        }
                    }
                }
            }
            if(dp[N]<=B) cur+=(1LL<<bit);
            else res+=(1LL<<bit);
        }
        cout<<res<<endl;
    }

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1;
    //cin>>t;
    while(t--){
        Solve();
    }
    return 0;
}

/*
6 1 3
8 1 2 1 5 4
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 272 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -