Submission #43252

#TimeUsernameProblemLanguageResultExecution timeMemory
43252trungproBali Sculptures (APIO15_sculpture)C++14
100 / 100
94 ms812 KiB
#include <bits/stdc++.h> #define LL long long using namespace std; const int N = 2005; LL sum[N],ans; bool f[N][N]; int dp[N],n,a,b; bool sub1(LL mask) { dp[0] = 0; for (int i = 1 ; i <= n ; ++ i) { dp[i] = b + 1; for (int j = i - 1 ; j >= 0 ; -- j) { if (((sum[i] -sum[j]) & ~mask) == 0) dp[i] = min(dp[i],dp[j]+1); } } return (dp[n] <= b); } bool sub2(LL mask) { f[0][0] = 1; for (int i = 1 ; i <= b ; ++ i) f[0][i] = 0; for (int i = 1 ; i <= n ; ++ i) { f[i][0] = 0; for (int j = 1 ; j <= b ; ++ j) { f[i][j] = 0; for (int k = 0 ; k < i ; ++ k) if (f[k][j-1] && ((sum[i] - sum[k]) & ~mask) == 0) f[i][j] = 1; } } for (int i = a; i <= b ; ++ i) if (f[n][i]) return 1; return 0; } bool check(LL mask) { if (a == 1) return sub1(mask); return sub2(mask); return 1; } int main() { //freopen(".inp","r",stdin); //freopen(".out","w",stdout); scanf("%d%d%d",&n,&a,&b); for (int i = 1 ; i <= n ; ++ i) { int val; scanf("%d",&val); sum[i] = sum[i-1] +(LL) val; } LL ans = (1LL << 41) - 1; for (int h = 40 ; h >= 0 ; -- h) { if (check(ans & (~(1LL << h)))) ans &= ~(1LL << h); // cout << ans << endl; } printf("%lld",ans); return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:59:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&a,&b);
                             ^
sculpture.cpp:63:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&val);
                         ^
#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...