Submission #151031

# Submission time Handle Problem Language Result Execution time Memory
151031 2019-09-01T15:16:27 Z AlexPop28 Bali Sculptures (APIO15_sculpture) C++11
0 / 100
2 ms 380 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF_LL = (1LL << 41) - 1;

void Solve(int n, int b, const vector<int> &v) {
  vector<vector<long long>> dp(n + 1, vector<long long>(b + 1, INF_LL));
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= b; ++j) {
      long long sum = 0LL;
      for (int k = i; k >= 1; --k) {
        sum += v[k];
        dp[i][j] = min(dp[i][j], dp[k - 1][j - 1] | sum);
      }
    }
  }
  cout << dp[n][b] << endl;
}

void SolveA1(int n, int b, const vector<int> &v) {
  vector<int> dp(n + 1);
  auto Check = [&](long long mask) {
    if ((v[1] | mask) != mask)
      return false;
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
      long long sum = 0LL;
      dp[i] = n + 1;
      for (int j = i; j >= 1; --j) {
        sum += v[j];
        if ((sum | mask) == mask)
          dp[i] = min(dp[i], dp[j - 1] + 1);
      } 
    }
    return dp[n] <= b;
  };

  long long ans = INF_LL;
  for (int bit = 40; bit >= 0; --bit) {
    if (Check(ans ^ (1LL << bit)))
      ans ^= 1LL << bit;
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, a, b; cin >> n >> a >> b;
  vector<int> v(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> v[i];
  if (a == 1) SolveA1(n, b, v);
  else Solve(n, b, v);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -