Submission #239123

#TimeUsernameProblemLanguageResultExecution timeMemory
239123jhnah917Bali Sculptures (APIO15_sculpture)C++14
100 / 100
352 ms512 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, a, b; int v[2020]; void solve1(){ int dp[2020]; // dp[i] = i까지 필요한 구간의 최소 개수 ll ans = 0; for(int i=41; ~i; i--){ memset(dp, 0x3f,sizeof dp); dp[0] = 0; for(int j=0; j<=n; j++){ ll now = 0; for(int k=j+1; k<=n; k++){ now += v[k]; if((now >> i) & 1) continue; ll ta = now >> (i + 1); ll tb = ans >> (i + 1); if(ta & ~tb) continue; dp[k] = min(dp[k], dp[j] + 1); } } if(dp[n] > b) ans |= (1LL << i); } cout << ans; exit(0); } void solve2(){ ll ans = 0; int dp[111][111]; // dp[i][j] = i번째까지 봤을 때, j개의 구간으로 만들 수 있는가? for(int i=41; ~i; i--){ memset(dp, 0, sizeof dp); dp[0][0] = 1; for(int j=0; j<=n; j++){ ll now = 0; for(int k=j+1; k<=n; k++){ now += v[k]; if((now >> i) & 1) continue; ll ta = now >> (i + 1); ll tb = ans >> (i + 1); if(ta & ~tb) continue; for(int s=0; s<n; s++) if(dp[j][s]) dp[k][s+1] = 1; } } int flag = 1; for(int j=a; j<=b; j++) if(dp[n][j]) { flag = 0; break; } if(flag) ans |= (1LL << i); } cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> a >> b; for(int i=1; i<=n; i++) cin >> v[i]; if(a == 1) solve1(); solve2(); }
#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...