Submission #610541

#TimeUsernameProblemLanguageResultExecution timeMemory
610541nohaxjustsofloBali Sculptures (APIO15_sculpture)C++17
100 / 100
180 ms16144 KiB
#include <bits/stdc++.h> #include <iostream> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set; mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count()); //uniform_int_distribution<int> gen; ///(min, max) //int random() {return gen(mt_rand);} const int mxN=2001; const int mod=998244353; const int mxlogN=40; const int mxK=26; const int inf=1e9; const int K=600; int dp[mxN][mxN], a[mxN], n, A, B; int vis[mxN]; ll check(int i, int k, ll msk, bool b) { if(!b) { if(i==n) return k>=A&&k<=B; if(~dp[i][k]) return dp[i][k]; ll sum=0; for(int j=i+1; j<=n; j++) { sum+=a[j-1]; if((msk&sum)==sum) if(check(j,k+1,msk,0)) return dp[i][k]=1; } return dp[i][k]=0; } else { queue<int> q; q.push(0); for(int i=0; i<=n; i++) vis[i]=0; while(q.size()) { int i=q.front(); q.pop(); ll sum=0; for(int j=i+1; j<=n; j++) { sum+=a[j-1]; if((msk&sum)==sum) { if(!vis[j]) { vis[j]=vis[i]+1; q.push(j); } } } } return vis[n]&&vis[n]<=B; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); for(int i=0; i<mxN; i++) for(int j=0; j<mxN; j++) dp[i][j]=-1; cin >> n >> A >> B; for(int i=0; i<n; i++) cin >> a[i]; ll msk=(1LL<<(mxlogN+1))-1; for(int j=0; j<=mxlogN; j++) { msk^=check(0,0,msk^1LL<<(mxlogN-j),n>100)<<(mxlogN-j); for(int i=0; i<mxN; i++) for(int j=0; j<mxN; j++) dp[i][j]=-1; } cout << msk << "\n"; } /* 6 2 2 8 1 2 1 5 4 */
#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...