結果

問題 No.2133 Take it easy!
ユーザー 👑 p-adicp-adic
提出日時 2022-11-26 17:28:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 3,153 bytes
コンパイル時間 3,603 ms
コンパイル使用メモリ 221,688 KB
実行使用メモリ 12,128 KB
最終ジャッジ日時 2024-10-03 01:29:07
合計ジャッジ時間 5,104 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
11,904 KB
testcase_01 AC 11 ms
11,904 KB
testcase_02 AC 10 ms
11,948 KB
testcase_03 AC 11 ms
12,004 KB
testcase_04 AC 12 ms
11,852 KB
testcase_05 AC 14 ms
12,068 KB
testcase_06 AC 16 ms
11,840 KB
testcase_07 AC 28 ms
11,880 KB
testcase_08 AC 30 ms
12,008 KB
testcase_09 AC 33 ms
11,864 KB
testcase_10 AC 32 ms
11,880 KB
testcase_11 AC 24 ms
11,856 KB
testcase_12 AC 28 ms
11,876 KB
testcase_13 AC 49 ms
11,988 KB
testcase_14 AC 52 ms
11,848 KB
testcase_15 AC 43 ms
11,880 KB
testcase_16 AC 37 ms
11,836 KB
testcase_17 AC 38 ms
11,876 KB
testcase_18 AC 55 ms
12,008 KB
testcase_19 AC 48 ms
11,932 KB
testcase_20 AC 21 ms
11,836 KB
testcase_21 AC 54 ms
11,992 KB
testcase_22 AC 38 ms
11,880 KB
testcase_23 AC 56 ms
12,128 KB
testcase_24 AC 56 ms
11,868 KB
testcase_25 AC 30 ms
11,880 KB
testcase_26 AC 10 ms
11,944 KB
testcase_27 AC 10 ms
11,876 KB
testcase_28 AC 10 ms
11,924 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