没啥思路看到题解,先处理最大值发现非常的nice

// Problem: C. Polycarp Recovers the Permutation
// Contest: Codeforces - Codeforces Round 756 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1611/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h&gt;
using namespace std;
using ll=long long;
const int N = 2e5+10;
int a[N];
void solve()
{
	int n;cin&gt;>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(a[1]!=n&amp;&amp;a[n]!=n){
		cout<<-1<<"n";
		return;
	}
	
	for(int i=n;i>=1;--i)cout<<a[i]<<" ";
	cout<<"n";
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;cin>>_;
	while(_--)solve();
	return 0;
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注