답안 #882607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882607 2023-12-03T12:13:39 Z vjudge1 Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 2508 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;


ll n, a, b, A[N], pref[N];


void solve(){
  cin >> n >> a >> b;
  for(int i = 1; i <= n; ++i) cin >> A[i];
  pref[0] = 0;
  for(int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + A[i];
  ll ans = 1e18;

  priority_queue<array<ll, 4>> Q;
  ll mn = 1e18, split = 1;
  for(int i = 1; i <= n; ++i){
    if(mn > (pref[i] | (pref[n] - pref[i]))) split = i, mn =  pref[i] | (pref[n] - pref[i]);
  }
  Q.push({-mn, split, 1, n});
  int x = 0;
  ans = 0;
  while(!Q.empty() && x < b){
    int l = Q.top()[2], r = Q.top()[3], spl = Q.top()[1];
    if(pref[r] - pref[l - 1] <= -Q.top()[0]){
      ans |= pref[r] - pref[l - 1];
      Q.pop();
      continue;
    }
    Q.pop();

    int vl = l, vr = spl;
    int pl = spl + 1, pr = r;

    


    l = vl, r = vr;
    ll mn = pref[r] - pref[l - 1];
    ll split = l;
    for(int j = l; j <= r; ++j){
      if(mn > ((pref[j] - pref[l - 1]) | (pref[r] - pref[j]))) split = j, mn = ((pref[j] - pref[l - 1]) | (pref[r] - pref[j]));
    }
    Q.push({-mn, split, l, r});

    l = pl, r = vr;
    mn = pref[r] - pref[l - 1];
    split = l;
    for(int j = l; j <= r; ++j){
      if(mn > ((pref[j] - pref[l - 1]) | (pref[r] - pref[j]))) split = j, mn = ((pref[j] - pref[l - 1]) | (pref[r] - pref[j]));
    }
    Q.push({-mn, split, l, r});

    ++x;
  }
  for(;!Q.empty();) ans |= pref[Q.top()[3]] - pref[Q.top()[2] - 1], Q.pop();


  cout << ans;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // cin >> tt;
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

sculpture.cpp: In function 'void solve()':
sculpture.cpp:41:23: warning: unused variable 'pr' [-Wunused-variable]
   41 |     int pl = spl + 1, pr = r;
      |                       ^~
sculpture.cpp: In function 'int main()':
sculpture.cpp:73:15: warning: unused variable 'aa' [-Wunused-variable]
   73 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2420 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -