結果

問題 No.2283 Prohibit Three Consecutive
ユーザー planesplanes
提出日時 2023-04-28 21:34:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 751 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 166,988 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 23:14:08
合計ジャッジ時間 2,447 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;

void solve() {

ll N;cin>>N;
string S;cin>>S;
for(ll i=0;i<N;i++) {
  ll a=i;
  ll b=i+1;
  ll c=i+2;
  a%=N;
  b%=N;
  c%=N;
  if(S[a]==S[b]&&S[b]==S[c]) {
    cout<<"NO"<<endl;
    return ;
  }

if(N>=5) {
  ll d=i-1;
  ll e=i-2;
  if(d<0) d+=N;
  if(e<0) e+=N;
  if(S[a]=='?'&&S[d]!='?'&&S[b]!='?') {
    if(S[d]!=S[b]&&S[d]==S[e]&&S[b]==S[c]) {
      cout<<"NO"<<endl;
      return ;
    }
  }
}
}

cout<<"YES"<<endl;

  


}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll t;cin>>t;
  for(ll i=0;i<t;i++) {
    solve();
  }

}


  
0