結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
odan3240
|
| 提出日時 | 2015-05-23 22:37:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,825 bytes |
| コンパイル時間 | 781 ms |
| コンパイル使用メモリ | 91,912 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2024-07-06 06:22:49 |
| 合計ジャッジ時間 | 1,507 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:67:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
67 | scanf("%d",&T);
| ~~~~~^~~~~~~~~
main.cpp:72:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
72 | scanf("%1s(%d,%d)",s,&n,&r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
template<class T,size_t N,T MOD>
struct Combination {
typedef T int_type;
vector<int_type> fact,factr,inv;
Combination() {
fact.resize(2*N+1);
factr.resize(2*N+1);
inv.resize(2*N+1);
fact[0]=factr[0]=1;
inv[1]=1;
for(int i=2;i<=2*N;i++) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
for(int i=1;i<=2*N;i++) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;
}
int_type C(int n, int r) {
if(r<0 || r>n) return 0;
return factr[r]*fact[n]%MOD*factr[n-r]%MOD;
}
int_type P(int n,int r) {
if(r<0 || r>n) return 0;
return fact[n]*factr[n-r]%MOD;
}
int_type H(int n, int r) {
if(n==0 && r==0) return 1;
return C(n+r-1,r);
}
};
int main() {
Combination<ll,100005,1000000007 > comb;
int T;
scanf("%d",&T);
char s[102];
int n,r;
rep(i,T) {
scanf("%1s(%d,%d)",s,&n,&r);
if(s[0]=='C') {
cout<<comb.C(n,r)<<endl;
}
if(s[0]=='P') {
cout<<comb.P(n,r)<<endl;
}
if(s[0]=='H') {
cout<<comb.H(n,r)<<endl;
}
}
return 0;
}
odan3240