結果

問題 No.2518 Adjacent Larger
ユーザー yumekawayuiyumekawayui
提出日時 2023-10-27 23:15:48
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,875 bytes
コンパイル時間 2,749 ms
コンパイル使用メモリ 188,408 KB
実行使用メモリ 4,628 KB
最終ジャッジ日時 2023-10-27 23:15:56
合計ジャッジ時間 4,954 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 6 ms
4,348 KB
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 20 ms
4,628 KB
testcase_17 AC 12 ms
4,348 KB
testcase_18 AC 12 ms
4,348 KB
testcase_19 AC 10 ms
4,348 KB
testcase_20 AC 15 ms
4,364 KB
testcase_21 AC 18 ms
4,628 KB
testcase_22 AC 17 ms
4,628 KB
testcase_23 AC 20 ms
4,628 KB
testcase_24 AC 17 ms
4,628 KB
testcase_25 AC 17 ms
4,628 KB
testcase_26 AC 17 ms
4,628 KB
testcase_27 AC 14 ms
4,628 KB
testcase_28 AC 17 ms
4,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/extc++.h>
using namespace std;
using ld = long double; 
const vector<int> dx = {0, 0, 1, -1};
const vector<int> dy = {1, -1, 0, 0};
#define vec vector
#define int long long
#define double long double
//cout<<setprecision(10)<<fixed<<..
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(i, x, n) for (int i = x; i < (int)(n); i++)
#define pii pair<int,int>
#define pq priority_queue

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;cin>>t;
    rep(i,t){
        int n;cin>>n;
        deque<int> A;
        set<int> S;
        rep(i,n){
            int a;
            cin>>a;S.insert(a);
            if(a==1&&i-1>=0&&A[i-1]==1){continue;}
            A.push_back(a);
        }
        if(*S.begin()==1){cout<<"No\n";continue;}
        bool f=true;
        n=A.size();
        if(A[0]==1){
            if(A[n-1]==2&&A[1]==2){f=false;}
            if(A[n-1]==0&&A[1]==0){f=false;}
        }
        if(A[0]==0){
            if(A[n-1]==0||A[1]==0){f=false;}
        }
        if(A[0]==2){
            if(A[n-1]==2||A[1]==2){f=false;}
        }
        int pos=A[0];
        for(int i=1;i<n;i++){
            if(!f){break;}
            if(A[i]==1){
                if((A[i-1]==0&&A[(i+1)%n]==0)||(A[i-1]==2&&A[(i+1)%n]==2)){
                    f=false;break;
                }
            }
            if(A[i]==0){
                if(pos==0){f=false;}
                if(A[i-1]==0||A[(i+1)%n]==0){f=false;break;}
                pos=0;
            }
            if(A[i]==2){
                if(pos==2){f=false;}
                if(A[i-1]==2||A[(i+1)%n]==2){f=false;break;}
                pos=2;
            }
        }
        if(f){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }

}
0