結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
imgry22
|
| 提出日時 | 2015-01-05 22:56:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,829 bytes |
| コンパイル時間 | 1,899 ms |
| コンパイル使用メモリ | 160,172 KB |
| 実行使用メモリ | 19,376 KB |
| 最終ジャッジ日時 | 2024-06-13 02:43:29 |
| 合計ジャッジ時間 | 2,147 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:56:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | scanf("%d%*c", &t);
| ~~~~~^~~~~~~~~~~~~
main.cpp:59:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
59 | scanf("%c(%d,%d)%*c", &q, &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:54:26: warning: iteration 2000000 invokes undefined behavior [-Waggressive-loop-optimizations]
54 | erep(i, 1, mn) fact[i] = (fact[i-1] * i) % MOD;
| ^
main.cpp:9:42: note: within this loop
9 | #define erep(i, m, n) for(ll (i)=(m); (i)<=(n); (i)++)
| ~~~^~~~~
main.cpp:54:3: note: in expansion of macro ‘erep’
54 | erep(i, 1, mn) fact[i] = (fact[i-1] * i) % MOD;
| ^~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++)
#define erep(i, m, n) for(ll (i)=(m); (i)<=(n); (i)++)
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rev(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }
#define INF 1000000000
#define MOD 1000000007LL
#define EPS 1E-9
const int MAX_N = 1000000;
const int mn = 2 * MAX_N + 1;
int n, k;
ll fact[mn];
int t;
char q;
ll extgcd(ll a, ll b, ll& x, ll& y)
{
ll d = a;
if(b != 0){
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
else{
x = 1;
y = 0;
}
return d;
}
ll modInverse(ll a, ll m)
{
ll x, y;
extgcd(a, m, x, y);
return (m + x % m) % m;
}
int main()
{
fact[0] = 1LL;
erep(i, 1, mn) fact[i] = (fact[i-1] * i) % MOD;
scanf("%d%*c", &t);
while(t--){
scanf("%c(%d,%d)%*c", &q, &n, &k);
if(q == 'C'){
if(n < k) cout << 0 << endl;
else cout << (fact[n] * modInverse((fact[k] * fact[n-k]) % MOD, MOD)) % MOD << endl;
continue;
}
if(q == 'P'){
if(n < k) cout << 0 << endl;
else cout << (fact[n] * modInverse(fact[n-k], MOD)) % MOD << endl;
continue;
}
if(q == 'H'){
if(n == 0) cout << 0 << endl;
else cout << (fact[n+k-1] * modInverse((fact[k] * fact[n-1]) % MOD, MOD)) % MOD << endl;
}
}
return 0;
}
imgry22