結果
問題 | No.117 組み合わせの数 |
ユーザー |
![]() |
提出日時 | 2015-01-05 02:38:57 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 107 ms / 5,000 ms |
コード長 | 1,238 bytes |
コンパイル時間 | 376 ms |
コンパイル使用メモリ | 44,492 KB |
実行使用メモリ | 32,768 KB |
最終ジャッジ日時 | 2024-06-13 02:41:04 |
合計ジャッジ時間 | 1,012 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:56:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 56 | scanf( "%d", &T ); | ~~~~~^~~~~~~~~~~~ main.cpp:60:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 60 | scanf( "%s", S ); | ~~~~~^~~~~~~~~~~
ソースコード
#include<cstdio>#include<cctype>#include<string>#define rep(i,a) for(int i=0;i<(a);++i)#define repd(i,a) for(int i=(a);i>=0;--i)typedef long long ll;const ll mod = 1000000007, MAX_N = 2000000;int T;ll fact[MAX_N+1], factinv[MAX_N+1];ll extgcd( ll a, ll b, ll &x, ll &y ){int d = b;if( b ){d = extgcd( b, a%b, y, x );y -= a/b*x;}elsex = 1, y = 0;return d;}ll divMod( ll a, ll b, ll m ){ll x, y;extgcd( b, m, x, y );return ((a*x)%m+m)%m;}ll perm( int n, int r ){ return n<r?0:fact[n]*factinv[n-r] % mod; }ll comb( int n, int r ){ return n<r?0:fact[n]*factinv[r] % mod * factinv[n-r] % mod; }ll homo( int n, int r ){ return r?comb( n+r-1, r ):1; }int main(){fact[0] = 1;rep( i, MAX_N )fact[i+1] = (i+1)*fact[i] % mod;factinv[MAX_N] = divMod( 1, fact[MAX_N], mod );repd( i, MAX_N-1 )factinv[i] = (factinv[i+1]*(i+1)) % mod;scanf( "%d", &T );rep( i, T ){char S[41];scanf( "%s", S );int n, r;ll ans = 0;if( sscanf( S, "C(%d,%d)", &n, &r ) == 2 )ans = comb(n,r);if( sscanf( S, "P(%d,%d)", &n, &r ) == 2 )ans = perm(n,r);if( sscanf( S, "H(%d,%d)", &n, &r ) == 2 )ans = homo(n,r);printf( "%lld\n", ans );}return 0;}