time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

Input

The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).

The second line contains n integers a1, a2, …, an (0 ≤ ai ≤ 109).

Output

Output the maximum value of a bitwise OR of sequence elements after performing operations.

Examples

input

3 1 2

1 1 1

output

3

input

4 2 3

1 2 4 8

output

79

Note

For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is .

For the second sample if we multiply 8 by 3 two times we’ll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.

【题目链接】:http://codeforces.com/contest/579/problem/D

【题解】



显然,二进制位1最靠左的那个数字乘上数字会让最靠左的数字再靠左一点;

这样做是最优的策略;

但是

如果有多个数字二进制1最靠左,即最靠左的1相同;则不能随便选;

比如

1 0 0 0

1 0 1 1

1 1 0 1

这3个数字;

假设要乘的数字x是2;只能乘1次;

这三个数字依次是

8

11

13

如果把2乘最大的那个数字13

0 1 0 0 0

0 1 0 1 1

1 1 0 1 0

最后取or运算

结果为1 1 0 1 1

如果把2乘8

1 0 0 0 0

0 1 0 1 1

0 1 1 0 1

则再取or运算

结果为

1 1 1 1 1

显然后者更大;

所以不能单纯地就认为乘那个最大的数字就好了;

但如果最靠左的1的位置不是所有数字中最靠左的;那就不可能去乘它了;

所以乘了一次之后;肯定是继续去乘刚才乘的数字;

比如刚才的乘2之后变成了

1 0 0 0 0

0 1 0 1 1

0 1 1 0 1

显然继续让那个10000乘2是更优的;因为最高位移动一下幅度更大;

枚举要乘哪个数字、然后一直乘就可以了;

处理出前缀or和后缀or;预处理出x^k;x为要乘的数字;k为允许乘的次数

【完整代码】

#include <bits/stdc++.h>
#define LL long long using namespace std; const int MAXN = 20e4+100; int n,k,x;
LL a[MAXN],qz[MAXN],hz[MAXN]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> n >> k >> x;
for (int i = 1;i <= n;i++)
cin >> a[i];
for (int i = 1;i <= n;i++)
qz[i] = qz[i-1] | a[i];
for (int i = n;i >= 1;i--)
hz[i] = hz[i+1] | a[i];
LL temp = x;
for (int i = 1;i <= k-1;i++)
temp*=x;
LL ans = 0;
for (int i = 1;i <= n;i++)
{
LL temp1 = a[i]*temp;
ans = max(ans,qz[i-1] | temp1 | hz[i+1]);
}
cout << ans << endl;
return 0;
}

【21.37%】【codeforces 579D】"Or" Game的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【35.37%】【codeforces 556C】Case of Matryoshkas

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【81.37%】【codeforces 734B】Anton and Digits

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【21.21%】【codeforces round 382D】Taxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【21.58%】【codeforces 746D】Green and Black Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 757D】Felicity's Big Secret Revealed

    [题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...

  7. 【codeforces 757E】Bash Plays with Functions

    [题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...

  8. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. 【30.23%】【codeforces 552C】Vanya and Scales

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 【微信】微信获取TOKEN,以及储存TOKEN方法,Spring quartz让Token永只是期

    官网说明 access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.开发人员须要进行妥善保存. access_token的存储至少要保留512个字符空间.ac ...

  2. StackExchange.Redis 官方文档(六) PipelinesMultiplexers

    原文:StackExchange.Redis 官方文档(六) PipelinesMultiplexers 流水线和复用 糟糕的时间浪费.现代的计算机以惊人的速度产生大量的数据,而且高速网络通道(通常在 ...

  3. Linux 内核源代码分析 chap 2 存储管理 (5)

    物理页面分配 linux 内核 2.4 中有 2 个版本号的物理页面分配函数 alloc_pages(). 一个在 mm/numa.c 中, 还有一个在 mm/page_alloc.c 中, 依据条件 ...

  4. 组件绑定v-model,实现最大化复用

    看优秀的vue项目,对组件的封装做的都非常到位,比如一个按钮都可以实现复用,仔细研究会发现实现基础就是组件直接绑定v-model,来看看按钮: 比如有个点赞按钮,长这样: 当点赞之后变成这样: 相信很 ...

  5. 利用IIdentify接口实现点选和矩形选择要素

    duckweeds 原文利用IIdentify接口实现点选和矩形选择要素 Identify接口定义了获得要素图层单个要素的属性的捷径方法.它有一个Identify方法,返回一个IArray数组对象. ...

  6. 是男人就下100层【第四层】——Crazy贪吃蛇(3)

    上一篇<是男人就下100层[第四层]--Crazy贪吃蛇(2)>实现了贪吃蛇绕着屏幕四周移动,这一篇我们来完成贪吃蛇的所有功能. 一.随机产生苹果 private void addAppl ...

  7. [SCSS] Loop Over Data with the SCSS @each Control Directive

    The SCSS @for directive is great when we know how many iterations are required and we only need 1 va ...

  8. 一起talk C栗子吧(第八十三回:C语言实例--进程间通信概述)

    各位看官们,大家好,前二回中咱们说的是进程停止的样例,这一回咱们说的样例是:进程间通信.闲话休提,言归正转.让我们一起talk C栗子吧! 看官们.每一个进程都拥有自己的资源,假设不同进程之间须要共享 ...

  9. 自定义控件三部曲之动画篇(一)——alpha、scale、translate、rotate、set的xml属性及用法

    前言:这几天做客户回访,感触很大,用户只要是留反馈信息,总是一种恨铁不成钢的心态,想用你的app,却是因为你的技术问题,让他们不得不放弃,而你一个回访电话却让他们尽释前嫌,当最后把手机号留给他们以便随 ...

  10. CentOS7.1 KVM虚拟化之虚拟机快照(5)

    这里用之前克隆的虚拟机vm1-clone进行快照操作 注: 1.快照实际上做的是虚拟机的XML配置文件,默认快照XML文件在/var/lib/libvirt/qemu/snapshot/虚拟机名/下 ...