CF1145A.Thanos Sort
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Thanos sort 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.
灭霸排序 是一种超级反派排序算法,其工作方式如下:若数组尚未有序,则打一个响指*,移除数组的前半部分或后半部分,然后重复该过程。
给定一个输入数组,使用灭霸排序所能得到的最长有序数组的长度是多少?
*需配备无限手套。
输入格式
The first line of input contains a single number n (1≤n≤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 ai (1≤ai≤100) — the elements of the array.
输入的第一行包含一个整数 n(1≤n≤16)—— 表示数组的大小。保证 n 是 2 的幂。
输入的第二行包含 n 个以空格分隔的整数 ai(1≤ai≤100)—— 表示数组的元素。
输出格式
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.
返回使用灭霸排序(Thanos sort)所能得到的最长有序数组的长度。数组中的元素必须按非递减顺序排列。
输入输出样例
输入#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.
在第一个例子中,数组已经排好序,因此不需要拍手。
在第二个例子中,数组实际上包含一个长度为 4 的已排序子数组,但你无法在一次拍手中从数组的不同端移除元素。每次你只能移除整个前半部分或整个后半部分,因此你需要拍手两次才能得到一个包含 2 个元素的已排序数组。
在第三个例子中,数组按降序排列,因此你只能从最终的毁灭中拯救一个元素。
输入解题思路,AI测评打分。不知道怎么写?