Submission #168666

# Submission time Handle Problem Language Result Execution time Memory
168666 2019-12-14T23:29:17 Z Milki Bali Sculptures (APIO15_sculpture) C++14
0 / 100
193 ms 31992 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 2e3 + 5;

ll n, a, b, x[MAXN], prefix[MAXN], dp[MAXN][MAXN];
vector <int> v;

ll get(int lt, int rt){
  if(lt > 0)
    return prefix[rt] - prefix[lt - 1];
  else
    return prefix[rt];
}

vector <int> nxt[MAXN], tmp_nxt[MAXN];

int rek(int pos, int num, ll forbidden){
  if(pos < 0){
    if(num >= a && num <= b)
      return 1;
    else
      return 0;
  }
  if(dp[pos][num] != -1)
    return dp[pos][num];

  int ret = 0;
  bool ok = (sz(tmp_nxt[pos]) > 0);
  for(auto it : nxt[pos]){
    ll sum = get(it, pos);
    if((sum & forbidden) == 0){
      ret |= rek(it - 1, num + 1, forbidden);
      if(!ok)
        tmp_nxt[pos].pb(it);
    }
  }
  return dp[pos][num] = ret;
}

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

  cin >> n >> a >> b;
  REP(i, n)
    cin >> x[i];
  prefix[0] = x[0];
  FOR(i, 1, n)
    prefix[i] = prefix[i - 1] + x[i];
  REP(i, n) REP(j, i)
    nxt[i].pb(j);

  ll forbidden = 0, sol = 0;
  for(int i = 40; i >= 0; --i){
    memset(dp, -1, sizeof(dp));
    forbidden |= (1LL << i);
    if(!rek(n - 1, 0, forbidden)){
      forbidden ^= (1LL << i);
      sol |= (1LL << i);
    }
    else{
      REP(j, n)
        nxt[j] = tmp_nxt[j];
    }
    //TRACE("OK");
    REP(j, n)
      tmp_nxt[j].clear();

  }
  cout << sol;
}
# Verdict Execution time Memory Grader output
1 Correct 148 ms 31948 KB Output is correct
2 Incorrect 159 ms 31864 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 193 ms 31988 KB Output is correct
2 Incorrect 186 ms 31864 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 183 ms 31948 KB Output is correct
2 Incorrect 153 ms 31868 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 149 ms 31956 KB Output is correct
2 Incorrect 176 ms 31864 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 183 ms 31992 KB Output is correct
2 Incorrect 181 ms 31992 KB Output isn't correct
3 Halted 0 ms 0 KB -