Submission #1192269

#TimeUsernameProblemLanguageResultExecution timeMemory
1192269ChuanChenBali Sculptures (APIO15_sculpture)C++20
100 / 100
62 ms328 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int inf = 2e9; int n, A, B; ll sv[2005]; int dp1[2005]; //dp[i] := usando [1; i], qtd minimo de grupos para o resultado seja um submask do prefixo que temos //dp[i] = inf <=> não consigo bool dp2[105][105]; //dp[i][g] := true <=> consigo usar [1; i], separar em g grupos, tal que bit b é 0 e resultado é prefixo do que já tenho ll ans; bool isSubmask(int b, ll val){ return (ans>>b)==((ans>>b)|(val>>b)); } bool solve1(int b){ for(int i = 1; i <= n; i++) dp1[i] = inf; for(int i = 1; i <= n; i++){ for(int j = 0; j < i; j++){ //[1; i] = [1; j] U [j+1; i]; if(isSubmask(b, sv[i]-sv[j])) dp1[i] = min(dp1[i], dp1[j]+1); } } if(dp1[n] <= B) return true; return false; } bool solve2(int b){ for(int i = 1; i <= n; i++) for(int g = 1; g <= n; g++) dp2[i][g] = false; for(int i = 1; i <= n; i++) dp2[i][1] = isSubmask(b, sv[i]); for(int i = 1; i <= n; i++) for(int g = 1; g <= i; g++) if(dp2[i][g]) for(int x = 1; i+x <= n; x++) dp2[i+x][g+1] |= isSubmask(b, sv[i+x]-sv[i]); for(int g = A; g <= B; g++) if(dp2[n][g]) return true; return false; } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> A >> B; for(int i = 1; i <= n; i++){ int a; cin >> a; sv[i] = sv[i-1]+a; } for(int b = 40; b >= 0; b--){ if(A==1){ if(!solve1(b)) ans+=(1ll<<b); } else{ if(!solve2(b)) ans+=(1ll<<b); } } 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...