結果

問題 No.2283 Prohibit Three Consecutive
ユーザー 👑 p-adicp-adic
提出日時 2023-06-05 14:13:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 2,980 bytes
コンパイル時間 3,471 ms
コンパイル使用メモリ 226,064 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 09:34:09
合計ジャッジ時間 4,360 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 6 ms
4,376 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 14 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef DEBUG
  #define _GLIBCXX_DEBUG
  #define CERR( ANSWER ) cerr << ANSWER << "\n";
#else
  #pragma GCC optimize ( "O3" )
  #pragma GCC optimize( "unroll-loops" )
  #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
  #define CERR( ANSWER ) 
#endif
#include <bits/stdc++.h>
using namespace std;

#define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) )
#define TYPE_OF( VAR ) decay_t<decltype( VAR )>
#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr )
#define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE
#define CIN( LL , A ) LL A; cin >> A
#define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) )
#define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX )
#define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR )
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ )
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES )
#define QUIT return 0
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n"

int main()
{
  UNTIE;
  CEXPR( int , bound_T , 50000 );
  CIN_ASSERT( T , 1 , bound_T );
  CEXPR( int , bound_N , 100000 );
  const string O = "1";
  const string D[4][2] = { { "0" , "0" } , { "0" , "1" } , { "1" , "0" } , { "1" , "1" } };
  const string Yes = "Yes";
  const string No = "No";
  REPEAT( T ){
    CIN_ASSERT( N , 3 , bound_N );
    CIN( string , S );
    set<string> T{};
    const string S0 = S.substr( 0 , 1 );
    const string S1 = S.substr( 1 , 1 );
    FOR( i , 0 , 4 ){
      const string ( &Di )[2] = D[i];
      T.insert( ( S0 > O ? Di[0] : S0 ) + ( S1 > O ? Di[1] : S1 ) );
    }
    char f = 0;
    FOR_ITR( T , itr , end ){
      char a = 1;
      char b = 1;
      char c = 1;
      char d = 1;
      const string& t = *itr;
      FOR( i , 0 , 2 ){
	const string s = t.substr( i , 1 );
	const bool p = s != O;
	const bool q = s >= O;
	const char a_next = p ? c : 0;
	const char b_next = q ? a | c : 0;
	const char c_next = p ? b | d : 0;
	const char d_next = q ? b : 0;
	a = a_next;
	b = b_next;
	c = c_next;
	d = d_next;
      }
      FOR( i , 2 , N ){
	const string s = S.substr( i , 1 );
	const bool p = s != O;
	const bool q = s >= O;
	const char a_next = p ? c : 0;
	const char b_next = q ? a | c : 0;
	const char c_next = p ? b | d : 0;
	const char d_next = q ? b : 0;
	a = a_next;
	b = b_next;
	c = c_next;
	d = d_next;
      }
      FOR( i , 0 , 2 ){
	const string s = t.substr( i , 1 );
	const bool p = s != O;
	const bool q = s >= O;
	const char a_next = p ? c : 0;
	const char b_next = q ? a | c : 0;
	const char c_next = p ? b | d : 0;
	const char d_next = q ? b : 0;
	a = a_next;
	b = b_next;
	c = c_next;
	d = d_next;
      }
      f |= a | b | c | d;
    }
    COUT( f > 0 ? Yes : No );
  }
  QUIT;
}
0