답안 #151028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151028 2019-09-01T15:11:44 Z AlexPop28 Bali Sculptures (APIO15_sculpture) C++11
0 / 100
2 ms 508 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, vector<long long>(b + 1, INF_LL));
  dp[0][1] = v[0];
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j <= b; ++j) {
      long long sum = v[i];
      for (int k = i - 1; k >= 0; --k) {
        dp[i][j] = min(dp[i][j], dp[k][j - 1] | sum);
        sum += v[k];
      }
    }
  }
  cout << dp[n - 1][b] << endl;
}

void SolveA1(int n, int b, const vector<int> &v) {
  vector<int> dp(n);
  auto Check = [&](long long mask) {
    if ((v[0] | mask) != mask)
      return false;
    dp[0] = 1;
    for (int i = 1; i < n; ++i) {
      long long sum = v[i];
      dp[i] = n + 1;
      for (int j = i - 1; j >= 0; --j) {
        if ((sum | mask) == mask)
          dp[i] = min(dp[i], dp[j] + 1);
        sum += v[i];
      } 
    }
    return dp[n - 1] <= 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);
  for (int &x : v) cin >> x;
  if (a == 1) SolveA1(n, b, v);
  else Solve(n, b, v);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 508 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -