Submission #1192263

#TimeUsernameProblemLanguageResultExecution timeMemory
1192263ChuanChenBali Sculptures (APIO15_sculpture)C++20
71 / 100
448 ms1420 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n, A, B; ll sv[105]; bool dp[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 solve(int b){ for(int i = 1; i <= n; i++) for(int g = 1; g <= n; g++) dp[i][g] = false; for(int i = 1; i <= n; i++){ dp[i][1] = isSubmask(b, sv[i]); } for(int i = 1; i <= n; i++){ for(int g = 1; g <= i; g++) if(dp[i][g]){ // consigo usar [1..i], separar em g grupos, tal que bit b é 0 e resultado é prefixo do que já tenho for(int x = 1; i+x <= n; x++){ //consigo usar grupos [1; i] e grupo[i+1; x] só se grupos [1; i] fosse bom e que sum(i+1, x) n viola prefixo //sum(i+1, x) precisar ser bom dp[i+x][g+1] |= isSubmask(b, sv[i+x]-sv[i]); } } } cerr << "b = " << b << '\n'; for(int i = 1; i <= n; i++){ for(int g = 1; g <= i; g++) if(dp[i][g]){ cerr << i << ' ' << g << '\n'; } } for(int g = A; g <= B; g++) if(dp[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(!solve(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...