結果
問題 | No.2343 (l+r)/2 |
ユーザー |
![]() |
提出日時 | 2023-06-09 23:03:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 1,290 bytes |
コンパイル時間 | 2,308 ms |
コンパイル使用メモリ | 202,688 KB |
最終ジャッジ日時 | 2025-02-14 00:37:37 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 14 |
ソースコード
#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; } } bool f(ll n,vector<ll> &a){ a.push_back(INF); vector<ll> v; ll cnt=1; rep(i,n){ if(a[i]!=a[i+1]){ v.push_back(cnt); cnt=1; }else{ cnt++; } } ll m=v.size(); if(m==1) return false; if(9<=m) return true; vector<vector<bool>> dp(m,vector<bool>(2,false)); dp[0][0]=true; rep(i,m-1){ if(dp[i][0]){ dp[i+1][1]=true; } if(dp[i][1]){ dp[i+1][0]=true; if(2<=v[i]) dp[i+1][1]=true; } } return dp[m-1][1]; } void solve(){ ll n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; vector<ll> ra=a; reverse(all(ra)); if(f(n,a)||f(n,ra)) cout << "Yes\n"; else cout << "No\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll t; cin >> t; while(t--){ solve(); } }