제출 #26417

#제출 시각아이디문제언어결과실행 시간메모리
26417zscoderBali Sculptures (APIO15_sculpture)C++14
100 / 100
103 ms6128 KiB
#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; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; ll a[2001]; bool dp[2001][2001]; ll s[2001]; int dp2[2001]; ll sum(int l, int r) { if(l==0) return s[r]; return s[r]-s[l-1]; } const int INF =1000001; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll ans = 0; int n; cin>>n; int l,r; cin>>l>>r; for(int i=0;i<n;i++) { cin>>a[i]; s[i]=a[i]; if(i>0) s[i]+=s[i-1]; } ll ban = (1LL<<43)-1; for(int i = 42; i >= 0; i--) { if(l==1) { for(int i=0;i<n;i++) dp2[i]=INF; ban^=(1LL<<i); for(int i=0;i<n;i++) { ll cur=sum(0,i); if((cur|ban)==ban) { dp2[i]=1; } } for(int i=1;i<n;i++) { for(int j=0;j<i;j++) { ll cur=sum(j+1,i); if((cur|ban)==ban) { dp2[i]=min(dp2[j]+1,dp2[i]); } } //cerr<<i<<' '<<dp2[i]<<'\n'; } if(dp2[n-1]>r) { ans^=(1LL<<i); ban^=(1LL<<i); } } else { for(int i=0;i<=n;i++) { for(int j=0;j<n;j++) { dp[i][j]=0; } } ban^=(1LL<<i); for(int i=0;i<n;i++) { ll cur=sum(0,i); if((cur|ban)==ban) { dp[1][i]=1; } } for(int i=1;i<n;i++) { for(int j=0;j<n;j++) { if(dp[i][j]) { for(int k=j+1;k<n;k++) { ll cur=sum(j+1,k); if((cur|ban)==ban) { dp[i+1][k]=1; } } } } } bool pos=0; for(int i=l;i<=r;i++) { if(dp[i][n-1]) { pos=1; break; } } if(!pos) { ans^=(1LL<<i); ban^=(1LL<<i); } } } cout<<ans<<'\n'; }
#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...