Submission #25047

#TimeUsernameProblemLanguageResultExecution timeMemory
25047kajebiiiBali Sculptures (APIO15_sculpture)C++14
100 / 100
119 ms6340 KiB
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++) #define SZ(v) ((int)(v).size()) #define ALL(v) (v).begin(),(v).end() #define one first #define two second typedef long long ll; typedef pair<int, int> pi; const int INF = 0x3f2f1f0f; const ll LINF = 1ll * INF * INF; const int MAX_N = 2e3 + 100, LOG_NR = 43; int N, A, B, Nr[MAX_N]; bool Dy4[MAX_N][MAX_N]; int Dy5[MAX_N]; int main() { cin >> N >> A >> B; for(int i=1; i<=N; i++) scanf("%d", &Nr[i]); ll memo = 0, ans = 0; for(int s=LOG_NR-1; s>=0; s--) { ll nowS = 1ll << s; if(N <= 100 && A != 1) { for(int i=0; i<=N; i++) for(int j=0; j<=N; j++) Dy4[i][j] = false; Dy4[0][0] = true; for(int i=1; i<=N; i++) { ll now = 0; for(int j=i; j>=1; j--) { now += Nr[j]; if(now & memo) continue; if( (now & nowS) == 0) for(int k=0; k<=min(B, j-1); k++) if(Dy4[k][j-1]) Dy4[k+1][i] = true; } } bool isZero = false; for(int k=A; k<=B; k++) if(Dy4[k][N]) { memo += nowS; isZero = true; break; } if(!isZero) ans += nowS; } else { for(int i=0; i<=N; i++) Dy5[i] = INF; Dy5[0] = 0; for(int i=1; i<=N; i++) { ll now = 0; for(int j=i; j>=1; j--) { now += Nr[j]; if(now & memo) continue; if((now & nowS) == 0) Dy5[i] = min(Dy5[i], Dy5[j-1] + 1); } } bool isZero = false; if(Dy5[N] <= B) { memo += nowS; isZero = true; } if(!isZero) ans += nowS; } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:21:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf("%d", &Nr[i]);
                                             ^
#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...