結果
| 問題 | 
                            No.2518 Adjacent Larger
                             | 
                    
| コンテスト | |
| ユーザー | 
                             FplusFplusF
                         | 
                    
| 提出日時 | 2023-10-27 22:43:30 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 58 ms / 2,000 ms | 
| コード長 | 1,469 bytes | 
| コンパイル時間 | 1,847 ms | 
| コンパイル使用メモリ | 200,588 KB | 
| 最終ジャッジ日時 | 2025-02-17 15:32:27 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 28 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
void solve(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<vector<vector<ll>>> dp(n,vector<vector<ll>>(2,vector<ll>(2,0)));
    if(a[0]==0){
        dp[1][1][1]=true;
    }
    if(a[0]==1){
        dp[1][1][0]=true;
        dp[1][0][1]=true;
    }
    if(a[0]==2){
        dp[1][0][0]=true;
    }
    for(ll i=1;i<n-1;i++){
        rep(j,2){
            if(a[i]==0) dp[i+1][1][j]|=dp[i][0][j];
            if(a[i]==1){
                dp[i+1][1][j]|=dp[i][1][j];
                dp[i+1][0][j]|=dp[i][0][j];
            }
            if(a[i]==2) dp[i+1][0][j]|=dp[i][1][j];
        }
    }
    bool ok=false;
    if(a[n-1]==0){
        ok|=dp[n-1][0][0];
    }
    if(a[n-1]==1){
        ok|=dp[n-1][0][1];
        ok|=dp[n-1][1][0];
    }
    if(a[n-1]==2){
        ok|=dp[n-1][1][1];
    }
    ll cnt=0;
    rep(i,n){
        if(a[i]==1) cnt++;
    }
    if(ok&&cnt!=n) cout << "Yes\n";
    else cout << "No\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    while(t--){
        solve();
    }
}
            
            
            
        
            
FplusFplusF