結果

問題 No.2148 ひとりUNO
ユーザー 👑 p-adicp-adic
提出日時 2024-04-21 17:46:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 7,116 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 213,168 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 16:39:04
合計ジャッジ時間 5,312 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 26 ms
5,248 KB
testcase_02 AC 25 ms
5,248 KB
testcase_03 AC 26 ms
5,248 KB
testcase_04 AC 26 ms
5,248 KB
testcase_05 AC 26 ms
5,248 KB
testcase_06 AC 26 ms
5,248 KB
testcase_07 AC 26 ms
5,248 KB
testcase_08 AC 26 ms
5,248 KB
testcase_09 AC 26 ms
5,248 KB
testcase_10 AC 26 ms
5,248 KB
testcase_11 AC 26 ms
5,248 KB
testcase_12 AC 26 ms
5,248 KB
testcase_13 AC 26 ms
5,248 KB
testcase_14 AC 26 ms
5,248 KB
testcase_15 AC 25 ms
5,248 KB
testcase_16 AC 35 ms
5,248 KB
testcase_17 AC 37 ms
5,248 KB
testcase_18 AC 36 ms
5,248 KB
testcase_19 AC 36 ms
5,248 KB
testcase_20 AC 36 ms
5,248 KB
testcase_21 AC 35 ms
5,248 KB
testcase_22 AC 36 ms
5,248 KB
testcase_23 AC 34 ms
5,248 KB
testcase_24 AC 36 ms
5,248 KB
testcase_25 AC 35 ms
5,248 KB
testcase_26 AC 29 ms
5,248 KB
testcase_27 AC 29 ms
5,248 KB
testcase_28 AC 28 ms
5,248 KB
testcase_29 AC 29 ms
5,248 KB
testcase_30 AC 28 ms
5,248 KB
testcase_31 AC 29 ms
5,248 KB
testcase_32 AC 28 ms
5,248 KB
testcase_33 AC 28 ms
5,248 KB
testcase_34 AC 29 ms
5,248 KB
testcase_35 AC 29 ms
5,248 KB
testcase_36 AC 29 ms
5,248 KB
testcase_37 AC 28 ms
5,248 KB
testcase_38 AC 29 ms
5,248 KB
testcase_39 AC 3 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ( "O3" )
// #pragma GCC target ( "avx" )
#include <bits/stdc++.h>
using namespace std;

using uint = unsigned int;
using ll = long long;

#define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::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 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( A ) string A; getline( cin , A ) 
#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 FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ ) 
#define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; 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"; 
#define RETURN( ANSWER ) COUT( ANSWER ); QUIT 
#define DOUBLE( PRECISION , ANSWER ) cout << fixed << setprecision( PRECISION ) << ( ANSWER ) << "\n"; QUIT 

#define POWER( ANSWER , ARGUMENT , EXPONENT )				\
  TYPE_OF( ARGUMENT ) ANSWER{ 1 };					\
  {									\
    TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT );	\
    TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT );	\
    while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){			\
      if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){			\
	ANSWER *= ARGUMENT_FOR_SQUARE_FOR_POWER;			\
      }									\
      ARGUMENT_FOR_SQUARE_FOR_POWER *= ARGUMENT_FOR_SQUARE_FOR_POWER;	\
      EXPONENT_FOR_SQUARE_FOR_POWER /= 2;				\
    }									\
  }									\


#define POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO )		\
  TYPE_OF( ARGUMENT ) ANSWER{ 1 };					\
  {									\
    TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( MODULO + ( ARGUMENT ) % MODULO ) % MODULO; \
    TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT );	\
    while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){			\
      if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){			\
	ANSWER = ( ANSWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % MODULO;	\
      }									\
      ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT_FOR_SQUARE_FOR_POWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % MODULO; \
      EXPONENT_FOR_SQUARE_FOR_POWER /= 2;				\
    }									\
  }									\



// 通常の二分探索
#define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  ll ANSWER = MAXIMUM;							\
  {									\
    ll VARIABLE_FOR_BINARY_SEARCH_L = MINIMUM;				\
    ll VARIABLE_FOR_BINARY_SEARCH_U = ANSWER;				\
    ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \
    if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){		\
      VARIABLE_FOR_BINARY_SEARCH_L = ANSWER;				\
    } else {								\
      ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \
    }									\
    while( VARIABLE_FOR_BINARY_SEARCH_L != ANSWER ){			\
      VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \
      if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){		\
	VARIABLE_FOR_BINARY_SEARCH_L = ANSWER;				\
	break;								\
      } else {								\
	if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH > 0 ){		\
	  VARIABLE_FOR_BINARY_SEARCH_L = ANSWER;			\
	} else {							\
	  VARIABLE_FOR_BINARY_SEARCH_U = ANSWER;			\
	}								\
	ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \
      }									\
    }									\
  }									\
									\


// 二進法の二分探索
#define BS2( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  ll ANSWER = MINIMUM;							\
  {									\
    ll VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 = 1;			\
    ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( MAXIMUM ) - ANSWER; \
    while( VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 <= VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH ){ \
      VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 *= 2;			\
    }									\
    VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 /= 2;			\
    ll VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER;		\
    while( VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 != 0 ){		\
      ANSWER = VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 + VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2; \
      VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( TARGET ) - ( EXPRESSION ); \
      if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH == 0 ){		\
	VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER;		\
	break;								\
      } else if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH > 0 ){	\
	VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2 = ANSWER;		\
      }									\
      VARIABLE_FOR_POWER_FOR_BINARY_SEARCH_2 /= 2;			\
    }									\
    ANSWER = VARIABLE_FOR_ANSWER_FOR_BINARY_SEARCH_2;			\
  }									\
									\


template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : - a; }
template <typename T> inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - ( - a - 1 ) % p - 1; }


int main()
{
  UNTIE;
  CEXPR( int , bound_T , 1000 );
  CIN_ASSERT( T , 1 , bound_T );
  REPEAT( T ){
    CEXPR( int , bound_N , 200000 );
    CIN_ASSERT( N , 1 , bound_N );
    string colour[3] = { "R" , "G" , "B" };
    int count_d[3] = {};
    bool found[bound_N + 1][3] = {};
    bool found_Di_colour;
    FOR( i , 0 , N ){
      CIN( string , Ci );
      CIN_ASSERT( Di , 1 , N );
      found_Di_colour = false;
      FOR( c , 0 , 3 ){
	if( Ci == colour[c] ){
	  found[Di][c] = found_Di_colour = true;
	  count_d[c]++;
	  break;
	}
      }
      assert( found_Di_colour );
    }
    int count = 0;
    int lack = 0;
    FOR( c , 0 , 3 ){
      if( count_d[c] > 0 ){
	count++;
	if( lack == c ){
	  lack++;
	}
      }
    }
    if( count == 1 ){
      COUT( "YES" );
    } else if( count == 2 ){
      bool isolated = true;
      FOREQ( d , 1 , N ){
	bool ( &found_d_colour )[3] = found[d];
	if( found_d_colour[(lack+1)%3] && found_d_colour[(lack+2)%3] ){
	  isolated = false;
	  COUT( "YES" );
	  break;
	}
      }
      if( isolated ){
	COUT( "NO" );
      }
    } else {
      int count_multiple_d[3] = {};
      FOREQ( d , 1 , N ){
	count = 0;
	lack = 0;
	bool ( &found_d_colour )[3] = found[d];
	FOR( c , 0 , 3 ){
	  if( found_d_colour[c] ){
	    count++;
	    if( lack == c ){
	      lack++;
	    }
	  }
	}
	if( count == 2 ){
	  count_multiple_d[(lack+1)%3]++;
	  count_multiple_d[(lack+2)%3]++;
	} else if( count == 3 ){
	  FOR( c , 0 , 3 ){
	    count_multiple_d[c]++;
	  }
	}
      }
      int multiple = count_multiple_d[0] * count_multiple_d[1] * count_multiple_d[2];
      if( multiple == 0 ){
	COUT( "NO" );
      } else if( multiple == 1 ){
	COUT( ( count_d[0] == 1 || count_d[1] == 1 || count_d[2] == 1 ) ? "YES" : "NO" );
      } else {
	COUT( "YES" );
      }
    }
  }
  QUIT;
}
0