結果
| 問題 | No.2141 Enumeratest |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-10-26 18:31:09 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 2,245 bytes |
| コンパイル時間 | 2,157 ms |
| コンパイル使用メモリ | 193,572 KB |
| 最終ジャッジ日時 | 2025-02-08 12:48:44 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#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 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 REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES )
#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; \
} \
} \
#define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin );
int main()
{
constexpr const ll bound = 1000000;
CIN_ASSERT( N , 1 , bound );
CIN_ASSERT( M , 1 , bound );
CHECK_REDUNDANT_INPUT;
ll a = M / N;
ll b = M % N;
constexpr const ll P = 998244353;
ll inv[bound+1];
inv[1] = 1;
FOREQ( i , 2 , bound ){
inv[i] = P - ( ( inv[ P % i ] * ( P / i ) ) % P );
}
ll answer = 1;
FOREQ( i , a + 1 , M ){
answer = ( answer * i ) % P;
}
ll prod_inv = 1;
FOREQ( i , 2 , a ){
prod_inv = ( prod_inv * inv[i] ) % P;
}
N--;
POWER( prod_inv_power , prod_inv , N , P );
answer = ( answer * prod_inv_power ) % P;
ll& inv_a_plus = inv[a + 1];
POWER( inv_a_plus_power , inv_a_plus , b , P );
answer = ( answer * inv_a_plus_power ) % P;
RETURN( answer );
}