結果
| 問題 | No.1369 交換門松列・竹 |
| コンテスト | |
| ユーザー |
👑 Nachia
|
| 提出日時 | 2021-01-29 21:32:10 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,032 bytes |
| 記録 | |
| コンパイル時間 | 1,225 ms |
| コンパイル使用メモリ | 213,696 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2026-06-17 10:48:58 |
| 合計ジャッジ時間 | 5,606 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 29 TLE * 1 -- * 3 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
bool iskadomatsu(int a,int b,int c){
if(a==b||b==c||a==c) return false;
if(a<b&&b<c) return false;
if(a>b&&b>c) return false;
return true;
}
int N;
int A[50000];
void loop(){
scanf("%d",&N);
rep(i,N) scanf("%d",&A[i]);
int prob = -1;
vector<int> wrongs;
rep(i,N-2) if(!iskadomatsu(A[i],A[i+1],A[i+2])) wrongs.push_back(i);
prob=wrongs[0];
bool ans=false;
for(int l=prob; l<prob+3; l++){
rep(r,N){
bool ok=true;
swap(A[l],A[r]);
for(int w:wrongs) if(!iskadomatsu(A[w],A[w+1],A[w+2])) ok=false;
for(int i=max(0,l-2); i<min(N-2,l+2); i++) if(!iskadomatsu(A[i],A[i+1],A[i+2])) ok=false;
for(int i=max(0,r-2); i<min(N-2,r+2); i++) if(!iskadomatsu(A[i],A[i+1],A[i+2])) ok=false;
swap(A[l],A[r]);
if(ok) ans=true;
}
}
printf(ans?"Yes\n":"No\n");
}
int main(){
int T; scanf("%d",&T);
while(T--) loop();
return 0;
}
Nachia