結果

問題 No.1369 交換門松列・竹
ユーザー 沙耶花沙耶花
提出日時 2021-01-29 21:52:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,622 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 208,532 KB
実行使用メモリ 4,636 KB
最終ジャッジ日時 2023-09-09 15:15:43
合計ジャッジ時間 3,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 22 ms
4,380 KB
testcase_15 AC 24 ms
4,380 KB
testcase_16 AC 30 ms
4,380 KB
testcase_17 AC 32 ms
4,384 KB
testcase_18 AC 31 ms
4,380 KB
testcase_19 AC 26 ms
4,376 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 26 ms
4,380 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 31 ms
4,376 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 22 ms
4,380 KB
testcase_26 AC 22 ms
4,380 KB
testcase_27 AC 18 ms
4,380 KB
testcase_28 AC 5 ms
4,384 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 10 ms
4,572 KB
testcase_31 AC 10 ms
4,636 KB
testcase_32 AC 8 ms
4,376 KB
testcase_33 AC 32 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

bool is_kadomatsu(long long a,long long b,long long c){
	if(a==b||b==c||c==a)return false;
	if(b>a&&b>c)return true;
	if(b<a&&b<c)return true;
	return false;
}

int main(){
	
	int T;
	cin>>T;
	
	rep(_,T){
		int N;
		scanf("%d",&N);
		
		vector<long long> A(N);
		rep(i,N){
			scanf("%lld",&A[i]);
		}
		vector<int> ind;
		int cnt = 0;
		rep(i,N-2){
			if(is_kadomatsu(A[i],A[i+1],A[i+2]))continue;
			rep(j,3){
				ind.push_back(i+j);
			}
			cnt ++;
		}
		sort(ind.begin(),ind.end());
		ind.erase(unique(ind.begin(),ind.end()),ind.end());
	//	cout<<ind.size()<<endl;
		if(ind.size()>10){
			printf("No\n");
			continue;
		}
		bool f = false;
		rep(i,ind.size()){
			int x = ind[i];
			rep(j,N){
				int y = j;
				if(x==y)continue;
				int X = 0;
				vector<int> t;
				for(int k=x-2;k<=x;k++)t.push_back(k);
				for(int k=y-2;k<=y;k++)t.push_back(k);
				sort(t.begin(),t.end());
				t.erase(unique(t.begin(),t.end()),t.end());
				rep(l,t.size()){
					int k = t[l];
					if(k<0)continue;
					if(k+2>=N)break;
					if(!is_kadomatsu(A[k],A[k+1],A[k+2]))X++;
				}
				
				swap(A[x],A[y]);
				rep(l,t.size()){
					int k = t[l];
					if(k<0)continue;
					if(k+2>=N)break;
					if(!is_kadomatsu(A[k],A[k+1],A[k+2]))X--;
				}
				swap(A[x],A[y]);
				/*
				if(x==1&&y==2){
					cout<<X<<endl;
					cout<<cnt<<endl;
				}
				*/
				if(X==cnt){
					f=true;
					break;
				}
				
			}
			if(f)break;
		}
		
		if(f)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
		
	
    return 0;
}
0