結果

問題 No.2518 Adjacent Larger
ユーザー umezoumezo
提出日時 2023-10-27 22:15:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 4,135 ms
コンパイル使用メモリ 204,924 KB
実行使用メモリ 9,604 KB
最終ジャッジ日時 2023-10-27 22:15:47
合計ジャッジ時間 3,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,316 KB
testcase_01 AC 12 ms
8,328 KB
testcase_02 AC 13 ms
8,328 KB
testcase_03 AC 12 ms
8,328 KB
testcase_04 AC 12 ms
8,328 KB
testcase_05 AC 12 ms
8,328 KB
testcase_06 AC 7 ms
8,336 KB
testcase_07 AC 7 ms
8,336 KB
testcase_08 AC 7 ms
8,336 KB
testcase_09 AC 8 ms
8,336 KB
testcase_10 AC 8 ms
8,336 KB
testcase_11 AC 7 ms
8,352 KB
testcase_12 AC 7 ms
8,348 KB
testcase_13 AC 8 ms
8,344 KB
testcase_14 AC 7 ms
8,352 KB
testcase_15 AC 8 ms
8,352 KB
testcase_16 AC 18 ms
9,340 KB
testcase_17 AC 12 ms
8,812 KB
testcase_18 AC 12 ms
8,812 KB
testcase_19 AC 12 ms
8,548 KB
testcase_20 AC 14 ms
9,076 KB
testcase_21 AC 17 ms
8,812 KB
testcase_22 AC 16 ms
8,812 KB
testcase_23 AC 19 ms
9,604 KB
testcase_24 AC 17 ms
9,340 KB
testcase_25 AC 17 ms
9,604 KB
testcase_26 AC 18 ms
9,604 KB
testcase_27 AC 18 ms
9,604 KB
testcase_28 AC 17 ms
9,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

vector<array<double,3>> G[200200];
const double INF=1e9; 
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int t;
  cin>>t;
  while(t--){
    int n;
    cin>>n;
    vector<int> A(n);
    int sum=0,c0=-1,c2=-1;
    rep(i,n){
      cin>>A[i];
      sum+=A[i];
      if(A[i]==0) c0=i;
      if(A[i]==2) c2=i;
    }
    if(sum!=n || c0==-1 || c2==-1){
      cout<<"No\n";
      continue;
    }
    vector<int> B(n+1);
    rep(i,n) B[i]=A[(i+c0)%n];
    B[n]=B[0];
    bool b=true;
    int now=0;
    for(int i=0;i<n;i++){
      if(B[i]==0 && B[i+1]==0) b=false;
      if(B[i]==2 && B[i+1]==2) b=false;
      if(now==0 && B[i]==1 && B[i+1]==0) b=false;
      if(now==2 && B[i]==1 && B[i+1]==2) b=false;
      if(B[i]==2) now=2;
      if(B[i]==0) now=0;
    }
    if(b) cout<<"Yes\n";
    else cout<<"No\n";
  }
    
  return 0;
}
0