Submission #654217

#TimeUsernameProblemLanguageResultExecution timeMemory
654217nguyentunglamBali Sculptures (APIO15_sculpture)C++14
100 / 100
107 ms368 KiB
#include<bits/stdc++.h> #define forin(i, a, b) for(int i = a; i <= b; i++) #define forde(i, a, b) for(int i = a; i >= b; i--) #define forv(a, b) for(auto & a : b) #define fi first #define se second #define ii pair<int, int> #define endl "\n" using namespace std; const int N = 2010; long long res, s[N]; int f[N], n, a, b; bool g[110][110]; void sub5() { for(int bit = 40; bit >= 0; bit--) { memset(f, 127, sizeof(f)); f[0] = 0; for(int i = 1; i <= n; i++) for(int j = 0; j < i; j++) { long long sum = s[i] - s[j]; sum >>= bit; sum <<= bit; if ((res | sum) == res) f[i] = min(f[i], f[j] + 1); } if (f[n] > b) res |= (1LL << bit); } } void sub4() { for(int bit = 40; bit >= 0; bit--) { memset(g, 0, sizeof(g)); g[0][0] = 1; for(int i = 1; i <= n; i++) for(int j = 0; j < i; j++) { long long sum = s[i] - s[j]; sum >>= bit; sum <<= bit; if ((res | sum) == res) for(int k = 1; k <= b; k++) g[i][k] = max(g[i][k], g[j][k - 1]); } bool ok = 0; for(int k = a; k <= b; k++) ok |= g[n][k]; if (!ok) res |= (1LL << bit); } } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } cin >> n >> a >> b; for(int i = 1; i <= n; i++) { cin >> s[i]; s[i] += s[i - 1]; } if (a == 1) sub5(); else sub4(); cout << res; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:44:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:45:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:48:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:49:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...