欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
5111.Recovering BST
Recovering BST
CF1025D · Recovering BST
- 难度:2100
- 标签:brute force、dp、math、number theory、trees
- 链接:https://codeforces.com/problemset/problem/1025/D
- 时间限制:1 second 内存限制:256 megabytes
- 出现位置:Day17-树形DP-区间DP-计数DP;Day30-结营-个人错题重做-公共重测池-尖子拔高
英文原题面
Statement
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees! Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and sees his creation demolished, he'll get extremely upset. To not let that happen, Dima has to recover the binary search tree. Luckily, he noticed that any two vertices connected by a direct edge had their greatest common divisor value exceed . Help Dima construct such a binary search tree or determine that it's impossible. The definition and properties of a binary search tree can be found here.
Input
The first line contains the number of vertices (). The second line features distinct integers () — the values of vertices in ascending order.
Output
If it is possible to reassemble the binary search tree, such that the greatest common divisor of any two vertices connected by the edge is greater than , print "Yes" (quotes for clarity). Otherwise, print "No" (quotes for clarity).
样例
样例 1
输入:
6
3 6 9 18 36 108
输出:
Yes
样例 2
输入:
2
7 17
输出:
No
样例 3
输入:
9
4 8 10 12 15 18 33 44 81
输出:
Yes
样例解释(英文原文)
The picture below illustrates one of the possible trees for the first example.
The picture below illustrates one of the possible trees for the third example.
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |