#include using namespace std; #define MAIN main #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT // 入力フォーマットチェック用 // 余分な改行を許さない #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ); inline CEXPR( int , log_length , 17 ); class Order { public: inline Order() = default; template list > A( const bitset& N ) const; template bool operator()( const bitset& N , const bitset& M ) const; template bitset CNF( const bitset& N ) const; }; template list > Order::A( const bitset& N ) const { list > S{}; int i_prev = 0; FOR( i , 0 , L ){ if( N[i] == 1 ){ S.push_front( bitset( i - i_prev ) ); i_prev = i + 1; } } return S; } template bool Order::operator()( const bitset& N , const bitset& M ) const { list > A_N = move( A( N ) ); list > A_M = move( A( M ) ); auto itr_N = A_N.begin(); auto end_N = A_N.end(); auto itr_M = A_M.begin(); auto end_M = A_M.end(); while( itr_N != end_N && itr_M != end_M ){ bitset& Ni = *itr_N; bitset& Mi = *itr_M; if( operator()( Ni , Mi ) ){ return true; } else if( Ni != Mi ){ return false; } itr_N++; itr_M++; } return itr_M != end_M; } template bitset Order::CNF( const bitset& N ) const { list > A_N = move( A( N ) ); auto begin = A_N.begin(); auto end = A_N.end(); if( begin == end ){ return bitset( 0 ); } auto itr = begin; auto itr_prev = itr; { bitset& A_N_i = *itr; A_N_i = move( CNF( A_N_i ) ); itr++; } while( itr != end ){ bitset& A_N_i = *itr; A_N_i = move( CNF( A_N_i ) ); itr_prev++; itr++; } itr = itr_prev; bool searching = ( itr != begin ); while( searching ){ bitset& A_N_i = *itr; bool increasing = true; while( increasing ){ itr_prev = itr; itr_prev--; bitset& A_N_i_prev = *itr_prev; if( operator()( A_N_i_prev , A_N_i ) ){ if( itr_prev == begin ){ A_N.erase( itr_prev ); increasing = false; searching = false; } else { A_N.erase( itr_prev ); } } else { increasing = false; } } if( searching ){ searching = ( --itr != begin ); } } bitset answer{ 0 }; itr = A_N.begin(); while( itr != end ){ answer <<= 1; answer[0] = 1; answer <<= itr->to_ullong(); itr++; } return answer; } int MAIN() { UNTIE; CEXPR( int , length , 100000 ); CIN( bitset , N ); CIN( bitset , M ); CHECK_REDUNDANT_INPUT; Order ord{}; RETURN( ord.operator()( ord.CNF( N ) , ord.CNF( M ) ) ? "Yes" : "No" ); }