結果

問題 No.1369 交換門松列・竹
ユーザー kotatsugamekotatsugame
提出日時 2021-01-29 22:06:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 78,876 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 15:30:07
合計ジャッジ時間 2,584 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 19 ms
4,376 KB
testcase_14 AC 42 ms
4,380 KB
testcase_15 AC 79 ms
4,376 KB
testcase_16 AC 14 ms
4,380 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 AC 14 ms
4,380 KB
testcase_19 AC 79 ms
4,380 KB
testcase_20 AC 15 ms
4,376 KB
testcase_21 AC 80 ms
4,380 KB
testcase_22 AC 15 ms
4,376 KB
testcase_23 AC 14 ms
4,376 KB
testcase_24 AC 14 ms
4,376 KB
testcase_25 AC 17 ms
4,384 KB
testcase_26 AC 13 ms
4,380 KB
testcase_27 AC 19 ms
4,380 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 9 ms
4,380 KB
testcase_30 AC 18 ms
4,376 KB
testcase_31 AC 18 ms
4,380 KB
testcase_32 AC 15 ms
4,380 KB
testcase_33 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:12:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   12 | main()
      | ^~~~

ソースコード

diff #

#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 if(X.size()<=100)
		{
			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;
	}
}
0