A12533 | Thanos Sort
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
[Thanos sort](https://codegolf.stackexchange.com/questions/182221/implement-the-thanos-sorting-algorithm) is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers\* to remove the first or the second half of the items, and repeat the process.
Given an input array, what is the size of the longest sorted array you can obtain from it using Thanos sort?
\*Infinity Gauntlet required.
Given an input array, what is the size of the longest sorted array you can obtain from it using Thanos sort?
\*Infinity Gauntlet required.
输入格式
The first line of input contains a single number $n$ ( $1 \le n \le 16$ ) — the size of the array. $n$ is guaranteed to be a power of 2.
The second line of input contains $n$ space-separated integers $a_i$ ( $1 \le a_i \le 100$ ) — the elements of the array.
The second line of input contains $n$ space-separated integers $a_i$ ( $1 \le a_i \le 100$ ) — the elements of the array.
输出格式
Return the maximal length of a sorted array you can obtain using Thanos sort. The elements of the array have to be sorted in non-decreasing order.
输入输出样例
输入 #1
4 1 2 2 4
输出 #1
4
输入 #2
8 11 12 1 2 13 14 3 4
输出 #2
2
输入 #3
4 7 6 5 4
输出 #3
1
In the first example the array is already sorted, so no finger snaps are required.
In the second example the array actually has a subarray of 4 sorted elements, but you can not remove elements from different sides of the array in one finger snap. Each time you have to remove either the whole first half or the whole second half, so you'll have to snap your fingers twice to get to a 2-element sorted array.
In the third example the array is sorted in decreasing order, so you can only save one element from the ultimate destruction.
In the second example the array actually has a subarray of 4 sorted elements, but you can not remove elements from different sides of the array in one finger snap. Each time you have to remove either the whole first half or the whole second half, so you'll have to snap your fingers twice to get to a 2-element sorted array.
In the third example the array is sorted in decreasing order, so you can only save one element from the ultimate destruction.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted