// 誤解法(O(N^2 2^N)愚直解)チェック #pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #include #include #include #include using namespace std; using ll = long long; #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 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 FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- ) #define QUIT return 0 #define COUT( ANSWER ) cout << ( ANSWER ) << "\n" int MAIN() { UNTIE; CEXPR( int , bound_N , 100000 ); CIN_ASSERT( N , 1 , bound_N ); CEXPR( int , bound_B , 1000000000 ); CIN_ASSERT( B , 1 , bound_B ); bool inA[bound_N] = {}; ll powerA[bound_N]; ll one = 1; ll powerN = one << N; FOR( j , 0 , N ){ CIN_ASSERT( Aj , 1 , N ); powerA[j] = one << --Aj; int answer = 0; FOR( ta , 0 , powerN ){ ll& powerAj = powerA[j]; bool b = ( ta & powerAj ) == powerAj; FOREQINV( L , j-1 , 0 ){ b = ( ta & powerA[L] ) == 0 || b; } b ? ++answer < B ? answer : answer -= B : answer; } COUT( answer ); } QUIT; }