Submission #317032

#TimeUsernameProblemLanguageResultExecution timeMemory
317032zaneyuBali Sculptures (APIO15_sculpture)C++14
50 / 100
118 ms512 KiB
/*input 6 1 3 8 1 2 1 5 4 */ #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; //typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") //order_of_key #of elements less than x // find_by_order kth element typedef long long int ll; #define ld double #define pii pair<int,int> #define f first #define s second #define pb push_back #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() const ll maxn=2e3+5; const ll maxlg=__lg(maxn)+2; const ll INF64=4e18; const int INF=0x3f3f3f3f; const ll MOD=998244353; const ld PI=3.14159265358979323846; const ld eps=1e-9; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define MP make_pair ll mult(ll a,ll b){ a%=MOD; b%=MOD; return (a*b)%MOD; } ll mypow(ll a,ll b){ ll res=1LL; while(b){ if(b&1) res=mult(res,a); a=mult(a,a); b>>=1; } return res; } int arr[maxn]; int dp[maxn]; ll dp2[maxn][maxn]; int main(){ ios::sync_with_stdio(false),cin.tie(0); int n,a,b; cin>>n>>a>>b; REP1(i,n){ cin>>arr[i]; } ll ans=(1LL<<45)-1; if(a==1){ for(int x=44;x>=0;x--){ ans^=(1LL<<x); //cout<<ans<<'\n'; REP1(i,n){ dp[i]=INF; ll sum=arr[i]; for(int j=i-1;j>=0;j--){ if((sum|ans)==ans){ MNTO(dp[i],dp[j]+1); } sum+=arr[j]; } } //cout<<dp[n]<<'\n'; if(dp[n]>b){ ans^=(1LL<<x); } } } else{ for(int x=44;x>=0;x--){ ans^=(1LL<<x); REP1(i,n){ REP1(j,n){ dp2[i][j]=0; ll sum=arr[i]; for(int k=j-1;k>=0;k--){ if((sum|ans)==ans) dp2[i][j]|=dp2[k][j-1]; sum+=arr[k]; } } } bool ok=0; for(int j=a;j<=b;j++) if(dp2[n][j]) ok=1; if(!ok) ans^=(1LL<<x); } } cout<<ans; }
#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...