Submission #649187

#TimeUsernameProblemLanguageResultExecution timeMemory
649187ParsaSBali Sculptures (APIO15_sculpture)C++14
100 / 100
144 ms524 KiB
// In the name of God #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second typedef long long ll; #define int ll const int N = 2000 + 5, MOD = 1e9 + 7; int n, a[N], A, B; int dp[N]; bool dp2[N][N]; void solve() { if (n <= 100) return; ll ans = 0; int C = 46; for (int i = 0; i <= C; i++) ans ^= 1LL << i; for (int l = C; l >= 0; l--) { ans ^= 1LL << l; dp[0] = 0; for (int i = 1; i <= n; i++) { ll sum = 0; dp[i] = n + 1; for (int j = i; j >= 1; j--) { sum += a[j]; if ((sum & ans) == sum) { dp[i] = min(dp[i], dp[j - 1] + 1); } } } if (dp[n] > B) ans ^= 1LL << l; } cout << ans << '\n'; } void solve2() { if (n > 100) return; ll ans = 0; int C = 45; for (int i = 0; i <= C; i++) ans ^= 1LL << i; for (int l = C; l >= 0; l--) { ans ^= 1LL << l; dp2[0][0] = true; for (int j = 1; j <= B; j++) { for (int i = 1; i <= n; i++) { dp2[i][j] = false; ll sum = 0; for (int k = i; k >= 1; k--) { sum += a[k]; if ((sum & ans) == sum) { dp2[i][j] |= dp2[k - 1][j - 1]; } } } } bool ok = false; for (int j = A; j <= B; j++) ok |= dp2[n][j]; if (!ok) ans ^= 1LL << l; } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> A >> B; for (int i = 1; i <= n; i++) cin >> a[i]; solve(); solve2(); return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'void solve2()':
sculpture.cpp:41:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   41 |     if (n > 100)
      |     ^~
sculpture.cpp:43:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   43 |  ll ans = 0;
      |  ^~
#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...