# "Or" Game

You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make as large as possible, where denotes the bitwise OR.

Find the maximum possible value of after performing at most k operations optimally.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
#define rt return 0
#define fr freopen("in.txt","r",stdin)
#define fw freopen("out.txt","w",stdout)
#define ll long long
using namespace std;

int a[200010];
int pre[200010];
int old[200010];

int main()
{
int n, k, x;
cin >> n >> k >> x;
for (int i = 1; i <= n;i++)
{
cin >> a[i];
pre[i] = pre[i - 1] | a[i];
}
for (int i = n; i > 0; i--)
old[i] = old[i + 1] | a[i];
ll l = 1, ans = 0;
for (int i = 0; i < k; i++)
l *= (ll)x;
for (int i = 1; i <= n;i++)
{
ans = max(ans, (l*(ll)a[i]) | (ll)(pre[i - 1]) | (ll)(old[i + 1]));
}
cout << ans << endl;
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章："Or" Game 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)