제출 #1208921

#제출 시각아이디문제언어결과실행 시간메모리
1208921_bekhruzBitwise (BOI06_bitwise)C++20
15 / 100
1096 ms436 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const ll linf = 1e15;
#define int long long 
void solve() {  
  int n, p;
  cin >> n >> p;
  vector<int> a(n),b(n),k(p + 1);
  for (int i = 0; i < p;i++) {
    cin >> k[i];
    if (i) k[i] += k[i - 1];
  }
  for (int i = 0; i  <n;i++) cin >> a[i] >> b[i];
  k[p] = k[ p- 1];
  ll ans = 0,mx = 0;
  //for (int i = 0; i < p;i++) cerr << k[i] << " ";
  function<ll(int,int,int)> brute = [&](int id,int id2,ll cur)->ll{ 
    //cerr << id << " " << id2 << " " << k[id2] << " " << cur << "\n";
    if (id == k[id2]) {
   //   cerr << cur << "\n";
      return max(mx,cur);
    }
    for (int v = a[id]; v <= b[id];v++) {
      mx = max(mx,brute(id + 1,id2,(cur | v)));
    }
    return mx;
  };
  function<void(int,int)> brute2 = [&](int id,ll val){ 
   // cerr << val << " "<< id << "\n";
    if (id == p) {
 //     cerr << val << " ";
      ans = max(ans,val);
      return;
    }
    if (id == -1) {
      mx = 0;
      ll vv = brute(0,0,0);
    //  cerr << vv << "\n";
      brute2(id + 1, vv);
    }
    else if (id + 1 == p) {
      ans = max(ans,val);
//cerr << val << " " <<id << " ";
      return;
    }
    else mx = 0,brute2(id + 1,(val & brute(k[id],id + 1, 0)));
  };
  brute2(-1,0);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
 // cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
} 
#Verdict Execution timeMemoryGrader output
Fetching results...