結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー 👑 p-adicp-adic
提出日時 2022-10-02 23:46:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,815 bytes
コンパイル時間 1,141 ms
コンパイル使用メモリ 68,740 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 16:47:00
合計ジャッジ時間 2,570 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdint.h>
using namespace std;

using ll = long long;

#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) 
#define CIN( LL , A ) LL A; cin >> A 
#define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type
#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 POWER( ANSWER , VAR , EXPONENT_REF , MODULO )			\
  TYPE_OF( VAR ) ANSWER = 1;						\
  TYPE_OF( VAR ) VARIABLE_FOR_SQUARE_FOR_POWER = VAR;			\
  while( EXPONENT_REF != 0 ){						\
    if( EXPONENT_REF % 2 == 1 ){					\
      ANSWER = ( ANSWER * VARIABLE_FOR_SQUARE_FOR_POWER ) % MODULO;	\
    }									\
    VARIABLE_FOR_SQUARE_FOR_POWER = ( VARIABLE_FOR_SQUARE_FOR_POWER * VARIABLE_FOR_SQUARE_FOR_POWER ) % MODULO;	\
    EXPONENT_REF /= 2;							\
  }			


#include <cassert>

#define MAIN main


int MAIN()
{
  constexpr const ll bound_N = 1000000000000000000;
  CIN( ll , N );
  assert( 1 <= N && N <= bound_N );
  constexpr const int bound_M = 100000;
  CIN( int , M );
  assert( 1 <= M && M <= bound_M );
  if( N < M ){
    RETURN( 0 );
  }
  constexpr const ll P = 998244353;
  constexpr const ll two = 2;
  ll N_copy = N % ( P - 1 );
  POWER( answer , two , N_copy , P );
  ll inverse[bound_M];
  inverse[1] = 1;
  N %= P;
  ll combination = N;
  answer--;
  if( M != 1 ){
    answer = ( answer + P - N ) % P;
  }
  FOR( i , 2 , M ){
    inverse[i] = P - ( inverse[P % i] * ( P / i ) ) % P;
    combination = ( combination * ( N + 1 + P - i ) ) % P;
    combination = ( combination * inverse[i] ) % P;
    answer = ( answer + P - combination ) % P;
  }
  RETURN( answer );
}
0