题目

好题。没想出解法。

官方题解:

这个解法和 Small Multiple 那道题的解法有异曲同工之妙。

扩展

若把 $\mathsf{or}$ 改成 $\mathsf{and}$ 或者 $\mathsf{xor}$ 怎么解?

代码

int main() {
int n;
scan(n);
vi a(1 << n);
scan(a);
vpii b(1 << n);
rng (i, 0, 1 << n) {
b[i] = {i, -1};
} auto cmp = [&](int x, int y) {
if (x == y) return false;
if (x == -1) return false;
if (y == -1) return true;
return a[x] > a[y];
}; auto update = [&](pii &a, pii b) {
vi x{a.first, a.second, b.first, b.second};
sort(all(x), cmp);
UNIQ(x);
a = {x[0], x[1]};
}; rng (i, 0, 1 << n) {
rng (j, 0, n) {
if (!get_bit(i, j)) {
update(b[i | 1 << j], b[i]);
}
}
} int ans = 0;
rng (i, 1, 1 << n) {
chkmax(ans, a[b[i].first] + a[b[i].second]);
println(ans);
} return 0;
}

Exec Time: 206 ms.

但是改成

int main() {
int n;
scan(n);
vi a(1 << n);
scan(a);
vv<int> b(1 << n);
rng (i, 0, 1 << n) {
b[i] = {i};
} auto cmp = [&](int x, int y) {
return a[x] > a[y];
}; auto update = [&](vi &a, vi &b) {
vi tmp = a;
tmp.insert(tmp.end(), all(b));
sort(all(tmp), cmp);
UNIQ(tmp);
a = {tmp[0], tmp[1]};
}; rng (i, 0, 1 << n) {
rng (j, 0, n) {
if (!get_bit(i, j)) {
update(b[i | 1 << j], b[i]);
}
}
} int ans = 0;
rng (i, 1, 1 << n) {
chkmax(ans, a[b[i][0]] + a[b[i][1]]);
println(ans);
} return 0;
}

Exec Time 416 ms.

仅仅是把pair<int,int>改为vector<int>,为何二者运行时间悬殊?

ARC100E. Or Plus Max的更多相关文章

  1. AtCoder Regular Contest 100 (ARC100) E - Or Plus Max 其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/9251448.html 题目传送门 - ARC100E 题意 给定一个正整数 $n(n\leq 18)$. 然后 ...

  2. Kafka副本管理—— 为何去掉replica.lag.max.messages参数

    今天查看Kafka 0.10.0的官方文档,发现了这样一句话:Configuration parameter replica.lag.max.messages was removed. Partiti ...

  3. 排序算法----基数排序(RadixSort(L,max))单链表版本

    转载http://blog.csdn.net/Shayabean_/article/details/44885917博客 先说说基数排序的思想: 基数排序是非比较型的排序算法,其原理是将整数按位数切割 ...

  4. [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  5. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  6. BZOJ 4390: [Usaco2015 dec]Max Flow

    4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 113[Submi ...

  7. supervisor监管进程max file descriptor配置不生效的问题

    配置了 sudo vim /etc/security/limits.conf * soft nofile * hard nofile   单独起进程没问题, 放到supervisor下监管启动,则报错 ...

  8. Max double slice sum 的解法

    1. 上题目: Task description A non-empty zero-indexed array A consisting of N integers is given. A tripl ...

  9. 3ds max 渲染清晰面片的边缘

    3ds max的菜单栏 -> 渲染 -> 材质编辑器->精简材质编辑器,将面状打勾,如下图,就能渲染出面片清晰的图形.

随机推荐

  1. [Luogu] 天天爱跑步

    https://www.luogu.org/problemnew/show/P1600 https://www.zybuluo.com/wsndy-xx/note/1135243 乱写的暴力,这道题暴 ...

  2. HDU6223 Infinite Fraction Path bfs+剪枝

    Infinite Fraction Path 这个题第一次看见的时候,题意没搞懂就没做,这第二次也不会呀.. 题意:第i个城市到第(i*i+1)%n个城市,每个城市有个权值,从一个城市出发走N个城市, ...

  3. 第72节:Java中的数组

    https://www.jianshu.com/p/9ad176caa5bc

  4. Linux下MongoDB非正常关闭启动异常解决方法

    1.将配置信息写入一个文件中 vim mongo.conf 里面写如下内容: dbpath=/usr/local/mongodb/data/ logpath=/usr/local/mongodb/lo ...

  5. [CSP-S模拟测试]:B(期望DP)

    题目传送门(内部题151) 输入格式 第一行一个整数$N$. 第二行$N$个整数,第$i$个为$a_i$. 输出格式 一行一个整数,表示答案.为避免精度误差,答案对$323232323$取模. 即设答 ...

  6. SPOJ AMR12B 720

    这个题应该是个优先队列的模版题 当时比赛的时候没时间做先贴一下大神的代码好好学习学习 B - Gandalf vs the Balrog Time Limit:2000MS     Memory Li ...

  7. Nginx-HTTP之静态网页访问流程分析二

    11. HTTP 阶段执行 下面会依次执行以下阶段: NGX_HTTP_SERVER_REWRITE_PHASE: 在将请求的 URI 与 location 表达式匹配前,修改请求的 URI (所谓重 ...

  8. 后盾网lavarel视频项目---Vue项目使用vue-awesome-swiper轮播插件

    后盾网lavarel视频项目---Vue项目使用vue-awesome-swiper轮播插件 一.总结 一句话总结: vue中的插件的使用和js插件的使用一样的简单,只是vue插件的引入过程有些不同 ...

  9. 2159 -- Ancient Cipher

    Ancient Cipher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36074   Accepted: 11765 ...

  10. C# List中的ForEach

    ; List<string> aaa = new List<string>(){ "aaa", "bbb" }; aaa.ForEach ...