結果
| 問題 |
No.1369 交換門松列・竹
|
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2021-01-29 22:07:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,525 bytes |
| コンパイル時間 | 1,608 ms |
| コンパイル使用メモリ | 177,240 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-27 08:19:52 |
| 合計ジャッジ時間 | 2,913 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 WA * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=1e18;
bool kad(int a, int b, int c){
if(a==c)
return 0;
if(a>b&&b<c)
return 1;
if(a<b&&b>c)
return 1;
return 0;
}
int main(){
int t; cin >> t;
while(t--){
int n; cin >> n;
VI a(n); REP(i,n) cin >> a[i];
set<int> st;
REP(i,n-2){
if(!kad(a[i],a[i+1],a[i+2])){
st.insert(i);
st.insert(i+1);
st.insert(i+2);
}
}
VI nt;
for(auto x:st) nt.push_back(x);
if(nt.size()>10){
cout << "No" << endl;
continue;
}
int m=nt.size();
bool no=1;
REP(i,m){
REP(j,i){
swap(a[nt[i]],a[nt[j]]);
bool ok=1;
REP(k,n-2){
if(!kad(a[k],a[k+1],a[k+2])){
ok=0;
break;
}
}
if(ok){
cout << "Yes" << endl;
no=0;
break;
}
swap(a[nt[i]],a[nt[j]]);
}
if(!no)
break;
}
if(no)
cout << "No" << endl;
}
return 0;
}
Haa