Submission #75466

#TimeUsernameProblemLanguageResultExecution timeMemory
75466MiricaMateiBali Sculptures (APIO15_sculpture)C++14
100 / 100
118 ms5596 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2005; int v[MAX_N]; int dp1[MAX_N]; bool dp[MAX_N][MAX_N]; int n; long long pref; bool check1(int bit, int b) { dp1[0] = 0; for (int i = 1; i <= n; ++i) { dp1[i] = b + 1; long long s = 0; for (int j = i; j >= 1; --j) { s += v[j]; if (dp1[j - 1] != b + 1 && (s & pref) == 0) dp1[i] = min(dp1[i], 1 + dp1[j - 1]); } } return dp1[n] <= b; } bool check2(int bit, int a, int b) { memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= i; ++j) { long long s = 0; for (int k = i; k >= j - 1; --k) { s += v[k]; if (dp[k - 1][j - 1] == 1 && (s & pref) == 0) { dp[i][j] = 1; break; } } } } for (int i = a; i <= b; ++i) if (dp[n][i]) { return 1; } return 0; } bool sePoate(int bit, int a, int b) { pref |= (1LL << bit); if (a == 1) return check1(bit, b); else return check2(bit, a, b); } int main() { int a, b; scanf("%d%d%d", &n, &a, &b); for (int i = 1; i <= n; ++i) scanf("%d", &v[i]); for (int i = 41; i >= 0; --i) { if (!sePoate(i, a, b)) { pref ^= (1LL << i); } } printf("%lld", ((1LL << 42) - 1) ^ pref); return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:60:8: 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:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &v[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...