Submission #1244178

#TimeUsernameProblemLanguageResultExecution timeMemory
1244178wedonttalkanymoreBali Sculptures (APIO15_sculpture)C++20
50 / 100
56 ms328 KiB
#include <bits/stdc++.h>

using namespace std;

#define             fi  first
#define             se  second
#define     file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#ifdef LOCAL
  #include "debug.h"
#else
  #define debug(...)
#endif

template <class A, class B> bool minimize(A &a, B b)  { return a > b ? a = b, true : false; }
template <class A, class B> bool maximize(A &a, B b)  { return a < b ? a = b, true : false; }

const int N = 2005, LG = 41;

int n, L, R;
int a[N], f[N];

namespace sub4 {
  bool valid() {
    return n <= 100;
  }
  bool dp[105][105];
  void solve() {
    long long res = (1LL << LG) - 1;
    for (int b = LG - 1; ~b; --b) {
      res -= 1LL << b;
      memset(dp, 0, sizeof(dp));
      dp[0][0] = 1;
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
          if (!dp[i][j]) {
            continue;
          }
          long long sum = 0;
          for (int k = i + 1; k <= n; ++k) {
            sum += a[k];
            dp[k][j + 1] |= (sum & res) == sum;
          }
        }
      }
      bool ok = 0;
      for (int i = L; i <= R; ++i) {
        ok |= dp[n][i];
      }
      res += (long long) !ok << b;
    }
    cout << res;
    exit(0);
  }
}

void process() {
  cin >> n >> L >> R;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
//   if (sub4::valid()) {
//     sub4::solve();
//   }
//   assert(L == 1);
  long long res = (1LL << LG) - 1;
  for (int b = LG - 1; ~b; --b) {
    res -= 1LL << b;
    fill(f + 1, f + n + 1, N);
    for (int i = 0; i < n; ++i) {
      long long sum = 0;
      for (int j = i + 1; j <= n; ++j) {
        sum += a[j];
        if ((sum & res) == sum) {
          minimize(f[j], f[i] + 1);
        }
      }
    }
    res += (long long) (f[n] > R) << b;
  } 
  cout << res;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  file("A");
  // int t; cin >> t; while (t--)
  process();
  return 0;
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:7:62: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define     file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:85:3: note: in expansion of macro 'file'
   85 |   file("A");
      |   ^~~~
sculpture.cpp:7:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define     file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:85:3: note: in expansion of macro 'file'
   85 |   file("A");
      |   ^~~~
#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...