結果

問題 No.2518 Adjacent Larger
ユーザー FplusFplusFFplusFplusF
提出日時 2023-10-27 22:43:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 210,192 KB
実行使用メモリ 34,572 KB
最終ジャッジ日時 2023-10-27 22:43:35
合計ジャッジ時間 4,303 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 24 ms
4,348 KB
testcase_02 AC 25 ms
4,348 KB
testcase_03 AC 24 ms
4,348 KB
testcase_04 AC 24 ms
4,348 KB
testcase_05 AC 24 ms
4,348 KB
testcase_06 AC 14 ms
4,348 KB
testcase_07 AC 15 ms
4,348 KB
testcase_08 AC 15 ms
4,348 KB
testcase_09 AC 15 ms
4,348 KB
testcase_10 AC 14 ms
4,348 KB
testcase_11 AC 13 ms
4,348 KB
testcase_12 AC 15 ms
4,348 KB
testcase_13 AC 14 ms
4,348 KB
testcase_14 AC 13 ms
4,348 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 65 ms
34,044 KB
testcase_17 AC 36 ms
20,844 KB
testcase_18 AC 36 ms
21,372 KB
testcase_19 AC 31 ms
18,008 KB
testcase_20 AC 45 ms
25,596 KB
testcase_21 AC 63 ms
34,572 KB
testcase_22 AC 63 ms
34,572 KB
testcase_23 AC 63 ms
34,572 KB
testcase_24 AC 59 ms
32,988 KB
testcase_25 AC 61 ms
34,572 KB
testcase_26 AC 61 ms
34,572 KB
testcase_27 AC 60 ms
34,572 KB
testcase_28 AC 62 ms
34,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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