結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
|
| 提出日時 | 2016-11-28 13:18:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,285 bytes |
| コンパイル時間 | 1,752 ms |
| コンパイル使用メモリ | 168,340 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2024-11-27 12:36:11 |
| 合計ジャッジ時間 | 3,620 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int MOD7 = ( int ) 1e9 + 7;
const int MAXN = ( int ) 1e6;
const int MAXK = ( int ) 1e6;
int fact[ MAXN + MAXK ], inv_fact[ MAXN + MAXK ];
int int_pow( int x, int p ){
int res = 1;
while( p ){
if( p & 1 )
res = 1LL * res * x % MOD7;
p >>= 1;
x = 1LL * x * x % MOD7;
}
return res;
}
int inv( int x ){
return int_pow( x, MOD7 - 2 );
}
signed main(){
for( int i = fact[ 0 ] = inv_fact[ 0 ] = 1; i < MAXN + MAXK; ++i )
fact[ i ] = 1LL * fact[ i - 1 ] * i % MOD7,
inv_fact[ i ] = 1LL * inv_fact[ i - 1 ] * inv( i ) % MOD7;
int T; cin >> T;
for( int kase = 0; kase < T; ++kase ){
string S; cin >> S;
char type = S[ 0 ];
int N = 0, K = 0;
for( int i = 2; i < S.size(); ++i ){
if( S[ i ] == ',' ){
for( int j = i + 1; S[ j ] != ')'; ++j )
K = K * 10 + S[ j ] - '0';
break;
}
N = N * 10 + S[ i ] - '0';
}
if( type == 'C' )
cout << 1LL * fact[ N ] * inv_fact[ K ] % MOD7 * inv_fact[ N - K ] % MOD7 << endl;
else if( type == 'P' )
cout << 1LL * fact[ N ] * inv_fact[ N - K ] % MOD7 << endl;
else
cout << 1LL * fact[ N + K - 1 ] * inv_fact[ K ] % MOD7 * inv_fact[ N - 1 ] % MOD7 << endl;
}
return 0;
}