Submission #846238

#TimeUsernameProblemLanguageResultExecution timeMemory
846238vjudge1Bali Sculptures (APIO15_sculpture)C++17
100 / 100
67 ms596 KiB
#include <bits/stdc++.h> #define pll pair <long long, long long> #define fi first #define se second using namespace std; #define task "code" #define all(s) s.begin(), s.end() typedef long long ll; const int ar = 2e3+2; const ll mod = 998244353; const ll oo = 1e18; int n, p, q; ll sum[ar]; bool f[101][101]; ll dp[ar]; void sub1() { ll ans = 0; for(int bit = 40; bit >= 0; --bit) { memset(f, 0, sizeof f); f[0][0] = 1; ll tmp = ans | (1ll << bit); for(int j = 1; j <= q; ++j) for(int i = j; i <= n; ++i) for(int k = 1; k <= i; ++k) { ll tong = sum[i] - sum[k - 1]; f[i][j] |= (f[k - 1][j - 1] && ((tong & tmp) == 0)); } for(int i = p; i <= q; ++i) if(f[n][i]) { ans |= (1ll << bit); break; } } ll res = 0; for(int i = 0 ; i <= 40 ; ++i) if (ans >> i & 1 ^ 1) res |= (1ll << i); cout << res; } void sub2() { ll ans = 0; for(int bit = 40; bit >= 0; --bit) { memset(dp, 0x3f, sizeof dp); dp[0] = 0; ll tmp = ans | (1ll << bit); for(int i = 1; i <= n; ++i) for(int k = 1; k <= i; ++k) { ll tong = sum[i] - sum[k - 1]; if((tong & tmp) == 0 && dp[k - 1] < oo) dp[i] = min(dp[i], dp[k - 1] + 1); } if(dp[n] <= q) ans = tmp; } ll res = 0; for(int i = 0 ; i <= 40 ; ++i) if (ans >> i & 1 ^ 1) res |= (1ll << i); cout << res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> n >> p >> q; for(int i = 1; i <= n; ++i) { int a; cin >> a; sum[i] = sum[i - 1] + a; } if(p != 1 && n <= 100) sub1(); else sub2(); return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'void sub1()':
sculpture.cpp:41:22: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   41 |         if (ans >> i & 1 ^ 1) res |= (1ll << i);
      |             ~~~~~~~~~^~~
sculpture.cpp: In function 'void sub2()':
sculpture.cpp:62:22: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   62 |         if (ans >> i & 1 ^ 1) res |= (1ll << i);
      |             ~~~~~~~~~^~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         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...