結果
問題 | No.117 組み合わせの数 |
ユーザー | Ysmr_Ry |
提出日時 | 2015-01-05 02:21:55 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,135 bytes |
コンパイル時間 | 214 ms |
コンパイル使用メモリ | 25,216 KB |
実行使用メモリ | 32,944 KB |
最終ジャッジ日時 | 2024-06-13 02:41:02 |
合計ジャッジ時間 | 897 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルメッセージ
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 ); | ~~~~~^~~~~~~~~~~ main.cpp:50:27: warning: iteration 1999999 invokes undefined behavior [-Waggressive-loop-optimizations] 50 | fact[i+1] = (i+1)*fact[i] % mod; | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ main.cpp:4:31: note: within this loop 4 | #define rep(i,a) for(int i=0;i<(a);++i) | ^ main.cpp:49:9: note: in expansion of macro ‘rep’ 49 | rep( i, MAX_N ) | ^~~
ソースコード
#include<cstdio> #include<cstring> #include<cctype> #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], factinv[MAX_N]; 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; } else x = 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:perm(n,r)*factinv[r] % mod; } ll homo( int n, int r ) { return comb( n+r-1, r ); } 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[21]; scanf( "%s", S ); char buf[21]; *buf = *S; buf[1] = '\0'; strcat(buf, "(%d,%d)"); int n, r; sscanf( S, buf, &n, &r ); printf( "%lld\n", (*S=='C'?comb:*S=='P'?perm:homo)(n, r) ); } return 0; }