結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
|
| 提出日時 | 2015-01-19 23:18:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,828 bytes |
| コンパイル時間 | 838 ms |
| コンパイル使用メモリ | 92,120 KB |
| 実行使用メモリ | 18,816 KB |
| 最終ジャッジ日時 | 2024-06-22 19:08:22 |
| 合計ジャッジ時間 | 1,457 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
ソースコード
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
class Mod
{
static const int MOD = 1000000007;
long long a;
public:
Mod(){
a = 0;
}
Mod(long long x){
a = (x % MOD + MOD) % MOD;
}
const Mod operator+(const Mod& x) const{
return Mod(a + x.a);
}
const Mod operator-(const Mod& x) const{
return Mod(a - x.a);
}
const Mod operator*(const Mod& x) const{
return Mod(a * x.a);
}
const Mod operator/(const Mod& x) const{ // フェルマーの小定理、MODが素数である場合のみ有効
int b = MOD - 2;
long long c = x.a;
long long ret = 1;
while(b > 0){
if(b & 1){
ret *= c;
ret %= MOD;
}
c *= c;
c %= MOD;
b >>= 1;
}
return Mod(a * ret);
}
long long getValue(){
return a;
}
};
int main()
{
vector<Mod> f(2000001, 1);
for(int i=2; i<=2000000; ++i)
f[i] = f[i-1] * i;
int t;
cin >> t;
while(--t >= 0){
char ope, c;
int a, b;
cin >> ope >> c >> a >> c >> b >> c;
Mod ret = 0;
if(ope == 'P'){
if(a >= b)
ret = f[a] / f[a-b];
}
else{
if(ope == 'H')
a += b - 1;
if(a >= b)
ret = f[a] / f[b] / f[a-b];
}
cout << ret.getValue() << endl;
}
return 0;
}