結果
| 問題 |
No.117 組み合わせの数
|
| コンテスト | |
| ユーザー |
creep04
|
| 提出日時 | 2018-03-15 13:40:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 741 bytes |
| コンパイル時間 | 1,281 ms |
| コンパイル使用メモリ | 160,612 KB |
| 実行使用メモリ | 19,104 KB |
| 最終ジャッジ日時 | 2024-12-16 09:08:49 |
| 合計ジャッジ時間 | 2,602 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%1s(%lld,%lld)", c, &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int t;
char c[100];
ll n, k, f[2002002];
ll mpow(ll x, ll n = mod-2, ll m = mod) {
ll res = 1;
while (n>0) {
if (n&1) res = res * x %m;
x = x * x %m;
n >>= 1;
}
return res;
}
ll comb(ll n, ll k) {
if (k==0) return 1;
if (n<k) return 0;
return f[n] * mpow(f[k]) %mod * mpow(f[n-k]) %mod;
}
int main() {
f[0] = 1;
for (ll i = 1; i <= 2000000; ++i) f[i] = f[i-1]*i %mod;
scanf("%d", &t);
while (t--) {
scanf("%1s(%lld,%lld)", c, &n, &k);
cout << c << ' ' << n << ' ' << k << endl;
if (c[0]=='C') cout << comb(n,k) << endl;
else if (c[0]=='P') cout << comb(n,k) * f[k] %mod << endl;
else cout << comb(n+k-1,k) << endl;
}
}
creep04