結果
| 問題 | No.1369 交換門松列・竹 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-01-29 22:06:22 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,411 bytes | 
| コンパイル時間 | 847 ms | 
| コンパイル使用メモリ | 79,296 KB | 
| 実行使用メモリ | 10,624 KB | 
| 最終ジャッジ日時 | 2024-06-27 08:18:29 | 
| 合計ジャッジ時間 | 5,263 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 29 TLE * 1 -- * 3 | 
コンパイルメッセージ
main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~
            
            ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int T,N;
int A[50505];
bool f(int id)
{
	int x=A[id],y=A[id+1],z=A[id+2];
	return(x<y&&y>z||x>y&&y<z)&&x!=z;
}
main()
{
	cin>>T;
	for(;T--;)
	{
		cin>>N;
		for(int i=0;i<N;i++)cin>>A[i];
		vector<int>X;
		int out=0;
		for(int i=0;i+3<=N;i++)if(!f(i))
		{
			out++;
			X.push_back(i);
			X.push_back(i+1);
			X.push_back(i+2);
		}
		sort(X.begin(),X.end());
		X.erase(unique(X.begin(),X.end()),X.end());
		bool fn=false;
		if(X.size()<=7)
		{
			for(int i:X)for(int j=0;j<N;j++)if(i!=j)
			{
				vector<int>ch;
				for(int k=-2;k<=2;k++)
				{
					if(i+k>=0&&i+k+3<=N)ch.push_back(i+k);
					if(j+k>=0&&j+k+3<=N)ch.push_back(j+k);
				}
				sort(ch.begin(),ch.end());
				ch.erase(unique(ch.begin(),ch.end()),ch.end());
				int now=out;
				for(int k:ch)now-=!f(k);
				swap(A[i],A[j]);
				for(int k:ch)now+=!f(k);
				if(now==0)fn=true;
				swap(A[i],A[j]);
			}
		}
		else
		{
			for(int i:X)for(int j:X)if(i<j)
			{
				vector<int>ch;
				for(int k=-2;k<=2;k++)
				{
					if(i+k>=0&&i+k+3<=N)ch.push_back(i+k);
					if(j+k>=0&&j+k+3<=N)ch.push_back(j+k);
				}
				sort(ch.begin(),ch.end());
				ch.erase(unique(ch.begin(),ch.end()),ch.end());
				int now=out;
				for(int k:ch)now-=!f(k);
				swap(A[i],A[j]);
				for(int k:ch)now+=!f(k);
				if(now==0)fn=true;
				swap(A[i],A[j]);
			}
		}
		cout<<(fn?"Yes":"No")<<endl;
	}
}
            
            
            
        