結果

問題 No.1369 交換門松列・竹
ユーザー 👑 Nachia
提出日時 2021-01-29 21:32:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,032 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 195,356 KB
最終ジャッジ日時 2025-01-18 08:55:55
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31 TLE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void loop()’:
main.cpp:18:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   scanf("%d",&N);
      |   ~~~~~^~~~~~~~~
main.cpp:19:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |   rep(i,N) scanf("%d",&A[i]);
      |            ~~~~~^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:40:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |   int T; scanf("%d",&T);
      |          ~~~~~^~~~~~~~~

ソースコード

diff #

#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;
}
0