Submission #882719

#TimeUsernameProblemLanguageResultExecution timeMemory
882719mychecksedadBali Sculptures (APIO15_sculpture)C++17
100 / 100
90 ms4700 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 5000+100, M = 1e5+10, K = 52, MX = 30; ll n, a, b, A[N], pref[N], dp[N][N]; pair<ll, ll> DP[N]; ll sum(int i, int j){ return pref[j] - pref[i-1]; } bool check(ll val){ if(n <= 100){ for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) dp[i][j] = 0; dp[0][0] = 1; for(int i = 1; i <= n; ++i){ for(int j = 1; j <= i; ++j){ for(int k = 0; k < i; ++k){ if((sum(k + 1, i) & val) == 0) dp[i][j] |= dp[k][j - 1]; } } } bool ans = 0; for(int i = a; i <= b; ++i) ans |= dp[n][i]; return ans; } for(int i = 0; i <= n; ++i) DP[i] = {0, 0}; DP[0] = {1, 0}; for(int i = 1; i <= n; ++i){ for(int j = 0; j < i; ++j){ if((sum(j + 1, i) & val) == 0 && DP[j].first == 1){ if(DP[i].first == 0) DP[i] = {1, DP[j].second + 1}; else DP[i].second = min(DP[i].second, DP[j].second + 1); } } } return (DP[n].first && DP[n].second <= b); } void solve(){ cin >> n >> a >> b; for(int i = 1; i <= n; ++i) cin >> A[i]; pref[0] = 0; for(int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + A[i]; ll ans = 0; for(ll bit = 45; bit >= 0; --bit){ if(check(ans + (1ll<<bit))){ ans += (1ll<<bit); } } cout << (1ll<<46)-1-ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // cin >> tt; while(tt--){ solve(); en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:68:15: warning: unused variable 'aa' [-Wunused-variable]
   68 |   int tt = 1, aa;
      |               ^~
#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...