結果

問題 No.2518 Adjacent Larger
ユーザー donutholedonuthole
提出日時 2023-10-27 22:30:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 3,544 bytes
コンパイル時間 4,071 ms
コンパイル使用メモリ 222,512 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-10-27 22:30:31
合計ジャッジ時間 4,942 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 31 ms
4,348 KB
testcase_02 AC 32 ms
4,348 KB
testcase_03 AC 32 ms
4,348 KB
testcase_04 AC 36 ms
4,348 KB
testcase_05 AC 32 ms
4,348 KB
testcase_06 AC 11 ms
4,348 KB
testcase_07 AC 11 ms
4,348 KB
testcase_08 AC 10 ms
4,348 KB
testcase_09 AC 11 ms
4,348 KB
testcase_10 AC 11 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 9 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 31 ms
6,548 KB
testcase_17 AC 20 ms
5,228 KB
testcase_18 AC 19 ms
5,228 KB
testcase_19 AC 16 ms
4,964 KB
testcase_20 AC 23 ms
5,492 KB
testcase_21 AC 29 ms
6,548 KB
testcase_22 AC 29 ms
6,548 KB
testcase_23 AC 32 ms
6,548 KB
testcase_24 AC 28 ms
6,284 KB
testcase_25 AC 30 ms
6,548 KB
testcase_26 AC 30 ms
6,548 KB
testcase_27 AC 30 ms
6,548 KB
testcase_28 AC 31 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <compare>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
ll const mod = 998244353;
using mint = atcoder::modint998244353;

#define _REP_OVERLOAD(e1,e2,e3,_REP,...) _REP
#define _REP_2(i,x) for(ll i = 0; i < ll(x); i++)
#define _REP_3(i,x,y) for(ll i = ll(x); i < ll(y); i++)
#define rep(...) _REP_OVERLOAD(__VA_ARGS__, _REP_3, _REP_2)(__VA_ARGS__)

#define _IREP_OVERLOAD(e1,e2,e3,_IREP,...) _IREP
#define _IREP_2(i,x) for(ll i = ll(x); i > -1; i--)
#define _IREP_3(i,x,y) for(ll i = ll(x); i > ll(y); i--)
#define irep(...) _IREP_OVERLOAD(__VA_ARGS__, _IREP_3, _IREP_2)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define vec vector
#define _V1_OVERLOAD(e1,e2,e3,e4,_V1,...) _V1
#define _V1_2(type,name) vec<type> name
#define _V1_3(type,name,n) vec<type> name(n)
#define _V1_4(type,name,n,val) vec<type> name(n,val)
#define v1(...) _V1_OVERLOAD(__VA_ARGS__, _V1_4, _V1_3, _V1_2)(__VA_ARGS__)

#define _V2_OVERLOAD(e1,e2,e3,e4,e5,_V2,...) _V2
#define _V2_2(type,name) vec<vec<type>> name
#define _V2_3(type,name,h) vec<vec<type>> name(h)
#define _V2_4(type,name,h,w) vec<vec<type>> name(h,vec<type>(w))
#define _V2_5(type,name,h,w,val) vec<vec<type>> name(h,vec<type>(w,val))
#define v2(...) _V2_OVERLOAD(__VA_ARGS__, _V2_5, _V2_4, _V2_3, _V2_2)(__VA_ARGS__)

// struct Pos{ll y,x; auto operator<=>(const Pos&) const = default;};
// struct dPos{double y,x; auto operator<=>(const dPos&) const = default;};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const vec<Pos> Dir4={Pos(-1,0),Pos(1,0),Pos(0,-1),Pos(0,1)}; // UDLR
// const vec<Pos> Dir8={Pos(-1,0),Pos(1,0),Pos(0,-1),Pos(0,1),Pos(-1,-1),Pos(1,1),Pos(-1,1),Pos(1,-1)};
bool inRange(int lower, int val, int upper){return lower<=val && val<upper;}
// struct item{ll a; auto operator<=>(const item&) const = default;};

ll llinf=ll(1e18)*2+10;
double dinf=1e24;

int main()
{
    cout << fixed << setprecision(15);

    ll T,N;
    cin>>T;
    rep(_,T){
        cin>>N;
        v1(ll,A,N);
        rep(i,N) cin>>A[i];
        A.emplace_back(A[0]);

        bool flg=true;

        bool check=true;
        ll idx=-1;
        rep(i,N){
            if(A[i]!=1) 
            {
                idx=i;
                check=false;}
        }
        if(check){
            cout<<"No"<<'\n';
            continue;
        }

        ll state=0; // 2:up -2:down 1:up or flat -1:donw or flat -100:none 
        rep(i,idx,idx+N+1){
            ll n1,n2;
            n1=A[(i)%N];
            n2=A[(i+1)%N];

            if(n1==0){
                if(state==-1){
                    flg=false;
                    break;
                }
                state=-1;
            }else if(n1==2){
                if(state==2 || state==1){
                    flg=false;
                    break;
                }
                state=2;
            }else if(n1==1){

            }
        }
        if(flg){
            cout<<"Yes"<<'\n';
        }else{
            cout<<"No"<<'\n';
        }

        
    }

    

    return 0;

}

0