Submission #846303

#TimeUsernameProblemLanguageResultExecution timeMemory
846303vjudge1Bali Sculptures (APIO15_sculpture)C++17
37 / 100
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N1 = 1e2+5; const int N2 = 2e3+5; int n, p, q, a[N1], dp2[N2]; ll res = (1ll << 41)-1; bool dp1[N1][N1]; void sub1() { for(int i = 40; i >= 0; --i) { res ^= (1ll << i); memset(dp1, 0, sizeof(dp1)); dp1[0][0] = 1; for(int j = 1; j <= n; ++j) { for(int g = 1; g <= min(j, q); ++g) { for(int k = 0; k < j; ++k) { if(((a[j] - a[k]) & res) == (a[j] - a[k])) { dp1[j][g] |= dp1[k][g-1]; } } } } bool ok = 0; for(int j = p; j <= q; ++j) { ok |= dp1[n][j]; } if(!ok) res ^= (1ll << i); } cout << res; } void sub2() { for(int i = 40; i >= 0; --i) { res ^= (1ll << i); memset(dp2, 0x3f, sizeof(dp2)); dp2[0] = 0; for(int j = 1; j <= n; ++j) { for(int k = 0; k < j; ++k) { if(((a[j]-a[k]) & res) == (a[j]-a[k])) { dp2[j] = min(dp2[j], dp2[k]+1); } } } if(dp2[n] > q) res ^= (1ll << i); } cout << res; } signed main() { if(fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> p >> q; for(int i = 1; i <= n; ++i) { cin >> a[i]; a[i] += a[i-1]; } if(p == 1) sub2(); else sub1(); }

Compilation message (stderr)

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