Submission #98533

#TimeUsernameProblemLanguageResultExecution timeMemory
98533tincamateiBali Sculptures (APIO15_sculpture)C++14
100 / 100
99 ms512 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2000; const int MAX_N2 = 100; int dp1[1+MAX_N]; bool dp2[1+MAX_N2][1+MAX_N2]; int y[1+MAX_N]; long long dodp1(int n, int lim) { long long rez = 0LL; for(int l = 41; l >= 0; --l) { long long allowedSet = (rez | ((1LL << l) - 1)); for(int i = 1; i <= n; ++i) { long long s = 0LL; dp1[i] = n + 1; for(int j = i; j > 0; --j) { s += y[j]; if((s | allowedSet) == allowedSet) dp1[i] = min(dp1[i], dp1[j - 1] + 1); } } if(dp1[n] > lim) rez = (rez | (1LL << l)); } return rez; } long long dodp2(int n, int lim1, int lim2) { long long rez = 0LL; for(int l = 41; l >= 0; --l) { long long allowedSet = (rez | ((1LL << l) - 1)); dp2[0][0] = true; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= n; ++j) { long long s = 0LL; dp2[i][j] = false; for(int k = j; k > 0; --k) { s += y[k]; if((s | allowedSet) == allowedSet) dp2[i][j] |= dp2[i - 1][k - 1]; } } } bool ok = false; for(int i = lim1; i <= lim2; ++i) if(dp2[i][n]) ok = true; if(!ok) rez = (rez | (1LL << l)); } return rez; } int main() { #ifdef HOME FILE *fin = fopen("input.in", "r"); FILE *fout = fopen("output.out", "w"); #else FILE *fin = stdin; FILE *fout = stdout; #endif int n, a, b; fscanf(fin, "%d%d%d", &n, &a, &b); for(int i = 1; i <= n; ++i) fscanf(fin, "%d", &y[i]); if(a == 1) fprintf(fout, "%lld", dodp1(n, b)); else fprintf(fout, "%lld", dodp2(n, a, b)); #ifdef HOME fclose(fin); fclose(fout); #endif return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:69:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d%d%d", &n, &a, &b);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:71:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d", &y[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...