Submission #846046

#TimeUsernameProblemLanguageResultExecution timeMemory
846046vjudge1Bali Sculptures (APIO15_sculpture)C++17
100 / 100
58 ms4392 KiB
#include <bits/stdc++.h> #define task "test" #define pii pair<int, int> #define ll long long #define fi first #define se second #define pb push_back using namespace std; void io() { if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } } const int inf = 1e9; const int mod = 1e9+7; const int nmax = 2e3+5; int n, p, q, dp2[nmax]; ll a[nmax]; bool dp[nmax][nmax]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); io(); cin >> n >> p >> q; for(int i = 1; i <= n; ++i) { cin >> a[i]; a[i] += a[i-1]; } ll ans = (1ll << 41) - 1; if(p == 1) { for(int t = 40; t >= 0; --t) { for(int i = 1; i <= n; ++i) dp2[i] = inf; ans ^= 1ll << t; for(int i = 1; i <= n; ++i) { for(int k = 1; k <= i; ++k) { if((ans | (a[i] - a[k-1])) == ans) { dp2[i] = min(dp2[i], dp2[k-1] + 1); } } } if(dp2[n] > q) ans ^= (1ll << t); } } else { for(int t = 40; t >= 0; --t) { memset(dp, 0, sizeof(dp)); dp[0][0] = 1; ans ^= 1ll << t; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= n; ++j) { for(int k = 1; k <= i; ++k) { if((ans | (a[i] - a[k - 1])) == ans) { dp[i][j] |= dp[k-1][j-1]; } } } } bool ok = 0; for(int i = p; i <= q; ++i) if(dp[n][i] == 1) ok = 1; if (!ok) ans ^= 1ll<<t; } } cout << ans; }

Compilation message (stderr)

sculpture.cpp: In function 'void io()':
sculpture.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         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...