結果

問題 No.2133 Take it easy!
ユーザー 👑 p-adicp-adic
提出日時 2022-11-26 17:28:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 3,153 bytes
コンパイル時間 3,591 ms
コンパイル使用メモリ 218,148 KB
実行使用メモリ 12,132 KB
最終ジャッジ日時 2024-04-14 04:21:23
合計ジャッジ時間 5,815 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
12,052 KB
testcase_01 AC 9 ms
12,000 KB
testcase_02 AC 10 ms
11,868 KB
testcase_03 AC 10 ms
12,128 KB
testcase_04 AC 11 ms
11,876 KB
testcase_05 AC 13 ms
12,128 KB
testcase_06 AC 15 ms
12,000 KB
testcase_07 AC 26 ms
12,004 KB
testcase_08 AC 32 ms
11,872 KB
testcase_09 AC 32 ms
11,872 KB
testcase_10 AC 32 ms
12,132 KB
testcase_11 AC 23 ms
12,124 KB
testcase_12 AC 25 ms
12,000 KB
testcase_13 AC 48 ms
12,004 KB
testcase_14 AC 53 ms
11,848 KB
testcase_15 AC 45 ms
12,024 KB
testcase_16 AC 37 ms
11,996 KB
testcase_17 AC 39 ms
12,000 KB
testcase_18 AC 54 ms
12,016 KB
testcase_19 AC 47 ms
11,968 KB
testcase_20 AC 21 ms
12,000 KB
testcase_21 AC 54 ms
12,128 KB
testcase_22 AC 39 ms
12,000 KB
testcase_23 AC 59 ms
11,940 KB
testcase_24 AC 55 ms
12,056 KB
testcase_25 AC 27 ms
12,128 KB
testcase_26 AC 10 ms
11,968 KB
testcase_27 AC 9 ms
12,076 KB
testcase_28 AC 10 ms
12,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 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 RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT 

int main()
{
  UNTIE;
  CEXPR( ll , P , 998244353 );
  CEXPR( int , bound_N , 200000 );
  CIN_ASSERT( N , 1 , bound_N );
  CEXPR( int , bound_Q , 60 );
  CIN_ASSERT( Q , 0 , bound_Q );
  ll factorial[bound_N + 1];
  ll inverse[bound_N + 1];
  ll inverse_factorial[bound_N + 1];
  ll factorial_current = factorial[0] = factorial[1] = 1;
  ll inverse_factorial_current = inverse_factorial[0] = inverse_factorial[1] = inverse[1] = 1;
  FOREQ( i , 2 , bound_N ){
    factorial[i] = ( factorial_current *= i ) %= P;
    inverse_factorial[i] = ( inverse_factorial_current *= ( inverse[i] = P - ( ( inverse[P % i] * ( P / i ) ) % P ) ) ) %= P;
  }
  int N_half = N / 2;
  ll answer;
  if( N % 2 == 0 ){
    ( answer = factorial[N_half] * factorial[N_half] ) %= P;
  } else {
    ( answer = factorial[N_half + 1] * factorial[N_half] ) %= P;
    N++;
  }
  bitset<bound_N + 1> base[bound_Q * 2 + 2] = {};
  bitset<bound_N + 1> current;
  ( ( ( current = 0 ).flip() <<= bound_N - N ) >>= bound_N - ( N - 1 ) ) <<= 1;
  base[0] = current;
  int num = 1;
  int num_copy;
  bitset<bound_N + 1> div;
  REPEAT( Q ){
    CIN_ASSERT( Li , 1 , N );
    CIN_ASSERT( Ri , Li , N );
    ( ( ( current = 0 ).flip() <<= bound_N - Ri ) >>= bound_N - ( Ri - Li ) ) <<= Li;
    num_copy = num;
    FOR( i , 0 , num_copy ){
      bitset<bound_N + 1>& basei = base[i];
      div = basei & current;
      if( div != 0 && div != basei ){
	basei &= ~div;
	base[num] = div;
	num++;
      }
    }
  }
  CEXPR( int , length , bound_N / 2 );
  ll Cataran[length + 1];
  Cataran[0] = 1;
  FOREQ( i , 1 , length ){
    Cataran[i] = ( ( ( factorial[i+i] * inverse_factorial[i+1] ) % P ) * inverse_factorial[i] ) % P;
  }
  int count;
  FOR( i , 0 , num ){
    count = 0;
    bitset<bound_N + 1>& basei = base[i];
    FOREQ( j , 1 , N ){
      if( basei[j] == 1 ){
	count++;
      }
    }
    if( count % 2 == 0 ){
      ( answer *= Cataran[count / 2] ) %= P;
    } else {
      answer = 0;
      break;
    }
  }
  RETURN( answer );
}
0